QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#685188#9528. New Energy Vehiclerrt517WA 0ms9752kbC++231.3kb2024-10-28 18:10:062024-10-28 18:10:07

Judging History

This is the latest submission verdict.

  • [2024-10-28 18:10:07]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 9752kb
  • [2024-10-28 18:10:06]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1000010,mod=1e9+7,eps=1e-9;
int a[N],x[N],tt[N],b[N];
int n,m;
void solve(){
	int n,m;
	cin>>n>>m;
	priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
	vector<vector<int>>ty(n+10);
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
		q.push({1e18,i});
	}
	for(int i=1;i<=m;i++){
		cin>>x[i]>>tt[i];
		ty[tt[i]].push_back(i);
		q.push({x[i],tt[i]});
	}
	for(int i=1;i<=n;i++){
		ty[i].push_back(1e18);

	}
	int now=0;
	for(int i=1;i<=m;i++){
		while(q.size() && q.top().first<x[i]) q.pop();
		while(q.size() && now<x[i]){
			auto t=q.top();
			q.pop();
			// cout<<i<<" "<<t.first<<"\n";
			int tmp=min(x[i]-now,a[t.second]);
			now+=tmp;	
			a[t.second]-=tmp;
			if(a[t.second]){
				q.push(t);
			}
		}
		if(now<x[i]){
			cout<<now<<"\n";
			return ;
		}
		a[tt[i]]=b[tt[i]];
		int pos=upper_bound(ty[tt[i]].begin(),ty[tt[i]].end(),i)-ty[tt[i]].begin();
		q.push({ty[tt[i]][pos],tt[i]});
		// for(int i=1;i<=n;i++){
		// 	cout<<a[i]<<" ";
		// }
		// cout<<"\n";
	}
	for(int i=1;i<=n;i++){
		now+=a[i];
	}
	cout<<now<<"\n";
}  
signed main(){

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

	


詳細信息

Test #1:

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

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

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'