QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#225496#7521. Find the GapPetroTarnavskyi#WA 0ms3552kbC++172.5kb2023-10-24 18:33:082023-10-24 18:33:09

Judging History

你现在查看的是最新测评结果

  • [2023-10-24 18:33:09]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2023-10-24 18:33:08]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const LL LINF = 1e18;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);
	int n;
	cin >> n;
	VI a(n), b(n), idxes(n);
	FOR(i, 0, n)
		cin >> a[i] >> b[i];
	iota(ALL(idxes), 0);
	sort(ALL(idxes), [&](int i, int j) {return b[i] < b[j];});
	vector<int> vec;
	int mn = INT_MAX;
	RFOR(i, n, 0)
	{
		if (b[idxes[i]] < mn)
		{
			mn = b[idxes[i]];
			vec.PB(i);
		}
	}
	reverse(ALL(vec));
	vector<LL> ans(n);
	int k = 0;
	multiset<int> sBig1, sSmall1, sBig2, sSmall2;
	LL sum1 = a[idxes[vec[0]]] + b[idxes[vec[0]]], sum2 = 0;
	FOR(j, 0, vec[0])
		sBig1.insert(a[idxes[j]]);
	if (SZ(vec) > 1)
	{
		FOR(j, 0, vec[1])
			sBig2.insert(a[idxes[j]]);
		sum2 = a[idxes[vec[1]]] + b[idxes[vec[1]]];
	}
	ans[0] = sum1;
	FOR(i, 0, SZ(vec) - 1)
	{
		while (k + 1 < n)
		{
			assert(!sBig2.empty());
			LL nsum1 = sum1 + (sBig1.empty() ? LINF : *sBig1.begin());
			LL nsum2 = sum2 + *sBig2.begin();
			if (nsum2 < nsum1)
				break;
			assert(!sBig1.empty());
			sum1 += *sBig1.begin();
			sSmall1.insert(*sBig1.begin());
			sBig1.erase(sBig1.begin());
			sum2 += *sBig2.begin();
			sSmall2.insert(*sBig2.begin());
			sBig2.erase(sBig2.begin());
			k++;
			ans[k] = sum1;
		}
		sum1 += a[idxes[vec[i + 1]]] + b[idxes[vec[i + 1]]] - (a[idxes[vec[i]]] + b[idxes[vec[i]]]);
		FOR(j, vec[i], vec[i + 1])
		{
			sum1 += a[idxes[j]];
			sSmall1.insert(a[idxes[j]]);
		}
		while (SZ(sSmall1) > k)
		{
			sum1 -= *prev(sSmall1.end());
			sBig1.insert(*prev(sSmall1.end()));
			sSmall1.erase(prev(sSmall1.end()));
		}
		if (i + 2 == SZ(vec))
			break;
		sum2 += a[idxes[vec[i + 2]]] + b[idxes[vec[i + 2]]] - (a[idxes[vec[i + 1]]] + b[idxes[vec[i + 1]]]);
		FOR(j, vec[i + 1], vec[i + 2])
		{
			sum2 += a[idxes[j]];
			sSmall2.insert(a[idxes[j]]);
		}
		while (SZ(sSmall2) > k)
		{
			sum2 -= *prev(sSmall2.end());
			sBig2.insert(*prev(sSmall2.end()));
			sSmall2.erase(prev(sSmall2.end()));
		}
		
	}
	while (k + 1 < n)
	{
		sum1 += *sBig1.begin();
		sSmall1.insert(*sBig1.begin());
		sBig1.erase(sBig1.begin());
		k++;
		ans[k] = sum1;
	}
	FOR(i, 0, n)
		cout << ans[i] << "\n";
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3552kb

input:

8
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

output:

3
4
5
6
7
8
10
12

result:

wrong answer 1st numbers differ - expected: '1.0000000', found: '3.0000000', error = '2.0000000'