Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

贴AC代码

Posted by Ioencgc at 2023-04-09 19:27:35 on Problem 2010
#include<iostream>
#include<stack>
#include<string.h>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<climits>
#include<cstdio>
#include<vector>
#include<sstream>
#include<ctype.h>
#include<set>
#include<map>
#include<ctime>
#include<stdlib.h>
#include<queue>
#include<bitset>
#define usi unsigned int
#define ull unsigned long long
using namespace std;
template<typename TTT>inline void mr(TTT& theNumberToRead)
{
	theNumberToRead = 0;
	bool prn = false;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')prn = true;
		c = getchar();
	}
	while (isdigit(c))
		theNumberToRead = 10 * theNumberToRead + (c ^ 48), c = getchar();
	if (prn)
		theNumberToRead = -theNumberToRead;
}
template<typename TTT>inline TTT mrr()
{
	TTT theNumberToRead = 0;
	bool prn = false;
	char c = getchar();
	while (!isdigit(c))
	{
		if (c == '-')prn = true;
		c = getchar();
	}
	while (isdigit(c))
		theNumberToRead = 10 * theNumberToRead + (c ^ 48), c = getchar();
	return prn ? -theNumberToRead : theNumberToRead;
}
template<typename T>void my_write(T x)
{
	if (x)
		my_write(x / 10),
		putchar(x % 10 ^ 48);
}
template<typename T>void mw(T x, char mid)
{
	if (x)
	{
		if (x < 0)
			putchar('-'),
			x = -x;
		my_write(x);
	}
	else putchar(48);
	if (mid)
		putchar(mid);
}
// ******************************************华丽的分割线******************************************
// ******************************************华丽的分割线******************************************
// ******************************************华丽的分割线******************************************
// ******************************************华丽的分割线******************************************
// ******************************************华丽的分割线******************************************
int dpl[100001], dpr[100001];
typedef pair<int, int>P;
priority_queue<int, vector<int>, less<int>>q;
P a[100001];
void qc()
{
	priority_queue<int, vector<int>, less<int>>em;
	swap(q, em);
}
int main()
{
	int n, c, f, m, sum = 0;
	mr(n), mr(c), mr(f);
	m = n - 1 >> 1;
	for (int i = 1; i <= c; ++i)
		mr(a[i].first), mr(a[i].second);
	sort(a + 1, a + c + 1);
	for (int i = 1; i <= m; ++i)
	{
		sum += a[i].second;
		dpl[i] = sum;
		q.push(a[i].second);
	}
	for (int i = m + 1; i <= c - m; ++i)
	{
		q.push(a[i].second);
		sum = sum + a[i].second - q.top();
		q.pop();
		dpl[i] = sum;
	}
	qc();
	sum = 0;
	for (int i = c; i > c - m; --i)
	{
		sum += a[i].second;
		dpr[i] = sum;
		q.push(a[i].second);
	}
	for (int i = c - m; i > m; --i)
	{
		q.push(a[i].second);
		sum = sum + a[i].second - q.top();
		q.pop();
		dpr[i] = sum;
	}
	for (int i = c - m; i > m; --i)
	{
		//mw(dpl[i] + dpr[i] - a[i].second, '\n');
		if (dpl[i - 1] + dpr[i + 1] + a[i].second <= f)
		{
			mw(a[i].first, '\n');
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator