QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#737305#9528. New Energy Vehiclewsxcb#WA 0ms3844kbC++171.1kb2024-11-12 15:25:272024-11-12 15:25:28

Judging History

This is the latest submission verdict.

  • [2024-11-12 15:25:28]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3844kb
  • [2024-11-12 15:25:27]
  • Submitted

answer

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

void solve() {

	int n, m;
	cin >> n >> m;

	vector<int> a(n + 1);
	for (int i = 1 ; i <= n ; i++)
		cin >> a[i];
	auto tmp = a;

	vector<int> x(m + 1), t(m + 1);
	for (int i = 1 ; i <= m ; i++)
		cin >> x[i] >> t[i];

	vector<int> last(m + 1), next(m + 1);
	for (int i = m ; i ; i--) {
		next[i] = last[t[i]];
		last[t[i]] = i;
	}

	priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
	for (int i = 1 ; i <= n ; i++) {
		q.push({last[i], i});
	}

	int ans = 0, jishu = 0;
	while (q.size()) {
		auto [P, id] = q.top();
		q.pop();

		int cur = x[jishu] - ans;
		if (jishu <= m && a[id] >= cur) {
			a[id] -= cur, ans += cur, a[jishu] = tmp[jishu];
			q.push({next[jishu], t[jishu]});
			if (id != t[jishu])
				q.push({P, id});
			jishu++;
		} else {
			ans += a[id];
			a[id] = 0;
		}
	}

	cout << ans << '\n';

}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

11
9

result:

wrong answer 1st lines differ - expected: '12', found: '11'