QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#698144#9528. New Energy VehiclewuyunzhishiWA 0ms3640kbC++201.3kb2024-11-01 17:41:172024-11-01 17:41:17

Judging History

This is the latest submission verdict.

  • [2024-11-01 17:41:17]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3640kb
  • [2024-11-01 17:41:17]
  • Submitted

answer

#include <bits/stdc++.h>
using ll = long long;
int inf = 0x3f3f3f3f;
void solve() {
	int n, m; std::cin >> n >> m;
	std::vector<ll> a(n + 1), x(m + 1, 0), t(m + 1, 0), able(m + 1, 0), prior(n + 1, inf);
	for(int i = 1; i <= n; i++) std::cin >> a[i];
	for(int i = 1; i <= m; i++) std::cin >> x[i] >> t[i];

	auto cmp = [&](int x, int y) {
		return prior[x] > prior[y];
	};
	std::priority_queue<int, std::vector<int>, decltype(cmp)> pq(cmp);
	std::vector g(n + 1, std::deque<int>());
	
	for(int i = 1; i <= m; i++) {
		g[t[i]].push_back(x[i]);
	}
	for(int i = 1; i <= n; i++) g[i].push_back(inf);
	for(int i = 1; i <= n; i++) prior[i] = g[i].front();
	for(int i = 1; i <= n; i++) pq.push(i);
	std::vector<ll> b = a;
	ll d = 0;
	for(int i = 1; i <= m; i++) {
		g[t[i]].pop_front();
		prior[t[i]] = g[t[i]].front();
		while(!pq.empty() && d < x[i]) {
			int u = pq.top();
			if(b[u] >= x[i] - d) {
				b[u] -= x[i] - d;
				d = x[i];
				if(u == t[i]) pq.pop();
				break;
			}
			else {
				d += b[u];
				b[u] = 0;
				pq.pop();
			}
		}
		if(pq.empty()) break;
		b[t[i]] = a[t[i]];
		pq.push(t[i]);
	}
	for(int i = 1; i <= n; i++) d += b[i];
	
	std::cout << d << '\n';
	
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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: 0ms
memory: 3568kb

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
11
999999999
1000000000

result:

wrong answer 6th lines differ - expected: '2000000000', found: '1000000000'