QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698598 | #9528. New Energy Vehicle | YSY2009# | WA | 1ms | 5996kb | C++14 | 1.5kb | 2024-11-01 20:43:01 | 2024-11-01 20:43:02 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
int a[100005];
int x[100005];
int t[100005];
int nw[100005];
priority_queue<pair<long long,int>,vector<pair<long long,int> >,greater<pair<long long,int> > > q;
long long lst[100005];
int pos[100005];
bool vis[100005];
void solve(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
nw[i]=a[i];
lst[i]=1e18;
}
for(int i=1;i<=m;i++){
scanf("%d%d",&x[i],&t[i]);
if(pos[t[i]]) lst[pos[t[i]]]=i;
pos[t[i]]=i;
if(!vis[t[i]]){
q.push(make_pair(x[i],t[i]));
vis[t[i]]=1;
}
}
for(int i=1;i<=n;i++)
if(!vis[t[i]]) q.push(make_pair(lst[i],i));
int id=1;
long long ans=0;
while(!q.empty()&&id<=m){
while(q.top().first<id){
pair<long long,int> x=q.top();
q.pop();
q.push(make_pair(lst[x.first],x.second));
}
int idx=q.top().second;
long long qwq=q.top().first;
q.pop();
if(ans+nw[idx]<=x[id]){
ans+=nw[idx];
nw[idx]=0;
}
else{
nw[idx]-=x[id]-ans;
ans=x[id];
}
if(nw[idx]) q.push(make_pair(qwq,idx));
if(ans>=x[id]){
nw[t[id]]=a[t[id]];
id++;
q.push(make_pair(lst[id],t[id]));
}
}
for(int i=1;i<=n;i++)
ans+=nw[i];
printf("%lld\n",ans);
for(int i=1;i<=m;i++)
lst[i]=0;
for(int i=1;i<=n;i++){
vis[i]=0;
pos[i]=0;
}
while(!q.empty()){
q.pop();
}
return;
}
int main(){
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5996kb
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: 3960kb
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 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'