QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#686249#9528. New Energy Vehicle369Pai#TL 0ms7588kbC++231.1kb2024-10-29 09:38:322024-10-29 09:38:33

Judging History

This is the latest submission verdict.

  • [2024-10-29 09:38:33]
  • Judged
  • Verdict: TL
  • Time: 0ms
  • Memory: 7588kb
  • [2024-10-29 09:38:32]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
int const N=1e5+10;
int n,m,a[N],nxt[N],x[N],nw[N],t[N],res[N];
inline void solve(){
	cin>>n>>m;
	int sm=0;
	rep(i,1,n) cin>>a[i],res[i]=a[i],sm+=a[i];
	rep(i,1,m) cin>>x[i]>>t[i];
	map<int,int>mp;
	per(i,m,1)
		if (mp.count(t[i])) nxt[i]=mp[t[i]];
		else nxt[i]=m+1;
	set< pair<int,int> >s;
	rep(i,1,n)
		if (mp.count(i)) nw[i]=m+1,s.insert({m+1,i});
		else nw[i]=mp[i],s.insert({mp[i],i});
	rep(i,1,m){
		if (x[i]>sm) break;
		int delta=x[i]-x[i-1];
		while (1){
			auto it=*s.begin();s.erase(it);
			int id=it.second;
			if (res[id]>delta){res[id]-=delta,s.insert(it);break;}
			else delta-=res[id],res[id]=0;
		}
		if (res[t[i]]) s.erase({nw[t[i]],t[i]});
		sm+=a[t[i]]-res[t[i]],res[t[i]]=a[t[i]];
		nw[t[i]]=nxt[i],s.insert({nw[t[i]],t[i]});
	}
	cout<<sm<<'\n';
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    int t;cin>>t;
    while (t--) solve();
    return 0;
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time Limit Exceeded

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:


result: