QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#685572#9528. New Energy VehiclePHarrWA 0ms3648kbC++201.2kb2024-10-28 20:13:412024-10-28 20:13:42

Judging History

This is the latest submission verdict.

  • [2024-10-28 20:13:42]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3648kb
  • [2024-10-28 20:13:41]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

using i32 = int32_t;
using i64 = long long;

#define int i64

using vi = vector<int>;
using pii = pair<int,int>;

const int inf = LLONG_MAX / 2;

void solve() {
	int n, m;
	cin >> n >> m;
	vi a(n + 1);
	for(int i = 1; i <= n; i ++) cin >> a[i];

	vi b = a;
	
	vector<pii> charge(m);
	for(auto &[x, t] : charge) cin >> x >> t;

	vi lst(n + 1, inf), suf(m + 1);
	
	for(int i = m - 1; i >= n; i --) {
		auto [pos, ti] = charge[i];
		suf[i] = lst[i], lst[ti] = i;
	}

	int now = 0;

	priority_queue<pii, vector<pii>, greater<pii>> bank;
	for(int i = 1; i <= n; i ++)
		bank.emplace(lst[i], i);

	for(int i = 0; i < m; i ++) {
		auto[x, t] = charge[i];
		while(now < x and not bank.empty()) {
			auto [it, p] = bank.top();
			bank.pop();
			int y = min(x - now, b[p]);
			now += y, b[p] -= y;
			if(b[p] > 0 and p != t) bank.emplace(it, p);
		}
		if(now == x) {
			b[t] = a[t];
			bank.emplace(suf[i], t);
		}else {
			break;
		}
	}
	for(auto i : b) {
		now += i;
	}
	cout << now << "\n";

}
i32 main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int T;
	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: 3648kb

input:

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

output:

12
8

result:

wrong answer 2nd lines differ - expected: '9', found: '8'