QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796130#9528. New Energy VehicleXiaoretaWWA 95ms19288kbC++201.6kb2024-12-01 12:45:512024-12-01 12:45:53

Judging History

This is the latest submission verdict.

  • [2024-12-01 12:45:53]
  • Judged
  • Verdict: WA
  • Time: 95ms
  • Memory: 19288kb
  • [2024-12-01 12:45:51]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long

struct node{
	int pos,id;
}b[100010];
int a[100010],now[100010];
int n,m;

bool cmp(node x,node y){
	return x.pos<y.pos;
}

void solve(){
	cin>>n>>m;
	set<pair<int,int>> q;
	set<int> p[n+10];
	vector<int> cnt(n+10,0);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		now[i]=a[i];
	}
	for(int i=1;i<=m;i++){
		cin>>b[i].pos>>b[i].id;
		p[b[i].id].insert(b[i].pos);
	}
	sort(b+1,b+1+m,cmp);
	for(int i=1;i<=m;i++){
		if(!cnt[b[i].id]) {
			q.insert({b[i].pos,b[i].id});
		}
		cnt[b[i].id]++;
	}
	int sum=0;
	for(int i=1;i<=n;i++){
		if(cnt[i]==0){
			sum+=a[i];
			now[i]=0;
		}
	}
	int ans=0;
	for(int i=1;i<=m;i++){
		if(!q.size()){
			break;
		}
		vector<pair<int,int>> del;
		for(auto [x,y]:q){
			int cha=b[i].pos-ans;
			ans+=min(now[y],cha);
			now[y]=max(0ll,now[y]-cha);
			if(now[y]==0ll){
				del.push_back({x,y});
			}
			if(ans>=b[i].pos){
				break;
			}
		}
		for(auto [x,y]:del){
			q.erase({x,y});
		}
		if(ans<b[i].pos){
			int cha=b[i].pos-ans;
			ans+=min(sum,cha);
			sum=max(0ll,sum-cha);
		}
		if(ans>=b[i].pos){
			now[b[i].id]=a[b[i].id];
			cnt[b[i].id]--;
			if(cnt[b[i].id]==0ll) {
				sum+=now[b[i].id];
				now[b[i].id]=0ll;
			}
			else{
				auto it=p[b[i].id].upper_bound(ans);
				if(it==p[b[i].id].end()){
					continue;
				}else{
					int index=*it;
					q.insert({index,b[i].id});					
				}
			}
		}
		else{
			break;
		}
	}
	cout<<ans+sum<<'\n';
	
}
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T=1;
	cin>>T; 
	while(T--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5652kb

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

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
Wrong Answer
time: 95ms
memory: 19288kb

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:

1543020
1578939
1345423
1527381
1547404
1564631
755120
1548178
840809
786564

result:

wrong answer 3rd lines differ - expected: '1526016', found: '1345423'