QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#749362#9528. New Energy VehiclebluejellyfishRE 0ms3500kbC++231.8kb2024-11-14 23:50:312024-11-14 23:50:31

Judging History

This is the latest submission verdict.

  • [2024-11-14 23:50:31]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 3500kb
  • [2024-11-14 23:50:31]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define x first
#define y second
using pii = pair<int,int>;
const int inf = 0x3f3f3f3f;
struct hui{
	int x,y;
	// bool operator <(const hui & k) const {
	// 	return k.x > x;
	// }
};
void miss() {
	int n,m;
	cin >> n >> m;
	vector<int>ai(n + 1),bi(n + 1);
	int tot = 0;
	for(int i = 1; i <= n; i++) {
		cin >> ai[i];
		bi[i] = ai[i];
		tot += ai[i];
	}
	hui q[m + 1];
	for(int i = 1; i <= m; i++) {
		cin >> q[i].x >> q[i].y;
	}
	q[0].x = q[0].y = 0;
	queue<int>a[n + 1];
	for(int i = 1; i <= m; i++) {
		a[q[i].y].push(i);
	}
	priority_queue<pii,vector<pii>,greater<>> qq;
	int sum = 0;
	for(int i = 1; i <= n; i++) {
		if(!a[i].empty()){qq.push({a[i].front(),i});a[i].pop();}
		else {sum += ai[i];ai[i] = 0;}
	}
	for(int i = 1; i <= m; i++) {
		int len = q[i].x - q[i - 1].x;
		queue<pii>qi;
		if(tot < len) {
			cout << q[i - 1].x + tot << endl;
			return;
		}
		while(len) {
			if(qq.empty()) {
				sum -= len;
				tot -= len;
				len = 0;
				break;
			}
			if(ai[qq.top().y] < len) {
				tot -= ai[qq.top().y];
				len -= ai[qq.top().y];
				auto it = qq.top();qq.pop();
				ai[it.y] = 0;
			}else {
				tot -= len;
				auto it = qq.top();qq.pop();
				ai[it.y] -= len;
				len = 0;
				qq.push(it);
			}
		}
		tot += bi[q[i].y] - ai[q[i].y];
		if(qq.top().x == i) qq.pop();
		if(a[q[i].y].size()) {
			int qwq = a[q[i].y].front();a[q[i].y].pop();
			qq.push({qwq,q[i].y});
			ai[q[i].y] = bi[q[i].y];
		}else {sum += bi[q[i].y];ai[q[i].y] = 0;}
	}
	int ans = q[m].x + sum;
	for(int i = 1; i <= n; i++) {
		ans += ai[i];
	}
	cout << ans << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    cin >> T;
    while(T--) miss();
	//system("pause");
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Runtime Error

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:

8

result: