QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#697805#9528. New Energy Vehicleczrq#RE 1ms5624kbC++171.5kb2024-11-01 15:51:152024-11-01 15:51:16

Judging History

This is the latest submission verdict.

  • [2024-11-01 15:51:16]
  • Judged
  • Verdict: RE
  • Time: 1ms
  • Memory: 5624kb
  • [2024-11-01 15:51:15]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int M=1e5+5;
ll id[M],a[M],n,m,k;
ll b[M];
ll nex[M];
bool vis[M]={0};
struct node{
	ll x,t;
	bool operator<(const node n) const
	{
		return x<n.x;
	}
}no[M];
bool cmp(node x,node y){
	return x.x<=y.x;
}
void solve(){
	cin>>n>>m;
	priority_queue<node> q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		b[i]=a[i];
		vis[i]=0;
		nex[i]=0;
		id[i]=0;
	}
	
	for(int i=1;i<=m;i++){
		cin>>no[i].x>>no[i].t;
		vis[no[i].t]=1;
		q.push(no[i]);
	}
	long long an=0;
	for(int i=1;i<=n;i++){
		if(vis[i]==0){
			an+=a[i];
		}
	}
	sort(no+1,no+1+m,cmp);
	for(int i=m;i>=1;i--){
		if(id[no[i].t]) nex[i]=id[no[i].t];
		id[no[i].t]=i;
	}
	int flag=0;
	long long sum=0;
	no[0].x=0;
	no[0].t=0;
	nex[0]=0;
	for(int i=0;i<m;i++){
		if(i>=1){
		if(nex[i]){
			q.push(no[nex[i]]);
			b[no[i].t]=a[no[i].t];
		}
		else{
			an+=a[no[i].t];
		}
		}


		
		while(q.size()&&no[i].x>=q.top().x)q.pop();
		
		long long res=no[i+1].x-no[i].x;
		while(res){
			if(!q.size()){
				an-=res;
				res=0;
				if(an<0){
					flag=1;
				}
			}
			int v=q.top().t;
			ll ans=min(res,b[v]);
			if(ans==b[v]){
				q.pop();
			}
			res-=ans;
			b[v]-=ans;
		}
			
			
		if(flag){
			sum=no[i+1].x+an;
//			cout<<i<<"#"<<an<<endl;
			break;
		}	
			
		}
		
		

			if(flag==0){
		sum=(no[m].x+an+a[no[m].t]);
	}
	
	cout<<sum<<endl;
	
	}
	

	
	
	


int main(){
	int t=1;
	cin>>t;
	while(t--){
		solve();
	}	
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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:

6

result: