QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#687732#9528. New Energy VehiclexunxxxxWA 1ms7880kbC++231.3kb2024-10-29 20:54:372024-10-29 20:54:38

Judging History

This is the latest submission verdict.

  • [2024-10-29 20:54:38]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 7880kb
  • [2024-10-29 20:54:37]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100010
int n,m;
int a[N],x[N],t[N],o[N];
int f[N];
vector<int>g[N];
void solve()
{
	cin>>n>>m;
	
	for(int i=1;i<=n;i++) cin>>a[i],o[i]=a[i],g[i].clear();
	
	
	for(int i=1;i<=m;i++) 
	{
		cin>>x[i]>>t[i];
		g[t[i]].push_back(i);//id¿ÉÒÔÔÚµÚ¼¸¸öλÖóäµç 
	}
	
	int s=0;//½ô¼±Çé¿öÏÂÓõ磬²»¿É³äµÄµç 
	for(int i=1;i<=n;i++) if(!g[i].size()) s+=a[i],a[i]=0;
	
	priority_queue<int,vector<int>,greater<int>>q;
	
	for(int i=1;i<=m;i++) q.push(i);
	

	for(int i=1;i<=m;i++)
	{
		int d=a[i]-a[i-1];
		while(d>0&&!q.empty())
		{
			int u=q.top();
			q.pop();
			
			if(u<i) continue;
			
			int id=t[u];
			
			int t=min(a[id],d);
			
			d-=t;
			
			a[id]-=t;
			
			if(a[id]>0) q.push(u);
		}
		
		if(d>0)
		{
			int t=min(d,s);
			s-=t;
			d-=t;
			if(d>0)
			{
				cout<<a[i]-d<<"\n";
				return ;
			}
		}
		
		a[t[i]]=o[t[i]];
		
		auto j=upper_bound(g[t[i]].begin(),g[t[i]].end(),i);
		if(j!=g[t[i]].end()) q.push(*j);
	}
	
	int ans=s+a[m];
	for(int i=1;i<=n;i++) ans+=a[i];
	cout<<ans<<"\n";
}


signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	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: 7880kb

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

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
9
4
9
1999999998
2000000000

result:

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