QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#683268#9528. New Energy Vehiclewoodie_0064#WA 0ms3756kbC++201.4kb2024-10-27 19:47:532024-10-27 19:47:53

Judging History

This is the latest submission verdict.

  • [2024-10-27 19:47:53]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3756kb
  • [2024-10-27 19:47:53]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 3;
int T;
int n, num;

typedef long long ll;
void work(){
	int n,m;cin >> n >> m;
	vector <ll> a(n);
	for(auto &x : a) cin >> x;
	vector <ll> c = a;
	vector <pair <ll,ll>> b(m);
	vector <vector <int>> p(n);
	for(int i = 0;i < m;i++) {
		cin >> b[i].first >> b[i].second;
		b[i].second -= 1;
		p[b[i].second].push_back(i);
	}
	ll sum = 0;
	set <int> st;
	for(int i = 0;i < n;i++) {
		if(p[i].size()) {
			reverse(p[i].begin(),p[i].end());
			st.insert(p[i].back());
		}else {
			sum += a[i];
			a[i] = 0;
		}
	}
	b.push_back({1e18,0});
	ll pos = 0;
	for(int i = 0;i < m;i++) {
		while(!st.empty()) {
			auto it = *st.begin();
//			cout << it << ' ';
			ll val = min(a[it],b[i].first - pos);
			pos += val;
			a[it] -= val;
			if(a[it]) break;
			st.erase(it);
		}
//		cout << pos << '\n';
		ll dis = min(b[i].first - pos,sum);
		pos += dis;
		sum -= dis;
		if(pos < b[i].first) break;
		int now = b[i].second;
		a[now] = c[now];
		p[now].pop_back();
		if(!p[now].empty()) st.insert({p[now].back()});
		else {
			sum += a[now];
			a[now] = 0;
		}
	}
//	for(int i = 0;i < n;i++) pos += a[i];
	cout << pos + sum << '\n';

}


int main(){
//	freopen("test.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> T;
	while(T--){
		work();
	}	
	return 0;
}

详细

Test #1:

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

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: 3620kb

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:

6
11
4
11
999999999
2000000000

result:

wrong answer 1st lines differ - expected: '9', found: '6'