QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#687361#9528. New Energy Vehiclewei177WA 17ms72200kbC++171.5kb2024-10-29 18:36:522024-10-29 18:36:52

Judging History

This is the latest submission verdict.

  • [2024-10-29 18:36:52]
  • Judged
  • Verdict: WA
  • Time: 17ms
  • Memory: 72200kb
  • [2024-10-29 18:36:52]
  • Submitted

answer

#include <bits/stdc++.h>
#define N 100005
typedef long long ll;
using namespace std;
ll rec[N],sy[N];
deque<ll> idex[N];
const ll inf = 2e18;
void solve()
{
	ll n, m;
	cin >> n >> m;
	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		cin >> rec[i];
		sy[i] = rec[i];
	}
	priority_queue<pair<ll,ll>,vector<pair<ll, ll>>,greater<pair<ll, ll>> > q;
	vector<int> vis(n + 5);
	for (int i = 1; i <= m; i++)
	{
		int x, t;
		cin >> x >> t;
		if (!vis[t])
		{
			vis[t] = 1;
			q.push({ x,t });
			continue;
		}
		idex[t].push_back(x);
	}
	for (int i = 1; i <= n; i++){
		if (!vis[i])
			q.push({ inf,i });
	}
	while (!q.empty())
	{
		pair<ll, ll> tmp = q.top();
		ll x = tmp.first, id = tmp.second;
		q.pop();
		if (sy[id] >= x - ans){
			ans = x;
			sy[id] = rec[id];
		}
		else
		{
			ll le = x - ans - sy[id];
			ans += sy[id];
			while (!q.empty() && le > 0)
			{
				pair<ll, ll> ttmp = q.top();
				ll xx = ttmp.first, iid = ttmp.second;
				if (sy[iid] >= le) {
					sy[iid] -= le;
					ans += le;
					le = 0;
				}
				else {
					le -= sy[iid];
					ans += sy[iid];
					sy[iid] = 0;
					q.pop();
				}
			}
			if (le > 0)
				break;
		}
		if(idex[id].empty()) q.push({ inf,id });
		else {
			q.push({ idex[id].front(),id });
			idex[id].pop_front();
		}
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 17ms
memory: 71720kb

input:

2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1

output:

12
9

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 72200kb

input:

6
3 2
2 2 2
6 1
7 1
2 2
3 3
2 1
6 2
2 3
2 2
5 1
7 2
9 1
2 2
3 3
2 1
6 2
1 1
999999999
1000000000 1
1 1
1000000000
1000000000 1

output:

9
11
4
13
999999999
2000000000

result:

wrong answer 4th lines differ - expected: '11', found: '13'