QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749273#9528. New Energy VehiclebluejellyfishTL 0ms3652kbC++231.8kb2024-11-14 23:18:232024-11-14 23:18:23

Judging History

This is the latest submission verdict.

  • [2024-11-14 23:18:23]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 3652kb
  • [2024-11-14 23:18:23]
  • 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].size()){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 > 0) {
			if(!qq.size()) {
				tot -= len;
				sum -= 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;
				if(a[it.y].size()) {it.x = a[it.y].front();qi.push(it);}
			}else {
				tot -= len;
				auto it = qq.top();qq.pop();
				ai[it.y] -= len;
				len = 0;
				if(a[it.y].size()) {it.x = a[it.y].front();qi.push(it);}
			}
		}
		while(qi.size()) {
			qq.push(qi.front());qi.pop();
		}
		tot += bi[q[i].y] - ai[q[i].y];
		ai[q[i].y] = bi[q[i].y];
	}
	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");
}

詳細信息

Test #1:

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

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: 0
Accepted
time: 0ms
memory: 3592kb

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
2000000000

result:

ok 6 lines

Test #3:

score: -100
Time Limit Exceeded

input:

10
230 8042
599 1039 69 1011 1366 824 14117 1523 806 5002 332 55 3769 996 359 1040 255 1135 3454 3609 6358 2509 3695 8785 3890 1304 3394 14611 33 89 2245 508 22 1043 10411 628 1279 714 903 585 7413 5099 845 148 4689 2110 8683 1613 143 3263 2599 110 244 3297 4742 1571 425 1822 15692 572 9397 328 1691...

output:

1516178
1560107
1282793
1512670
1517079
1558605
911123
1542777

result: