QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698596 | #9528. New Energy Vehicle | YSY2009# | WA | 0ms | 3940kb | C++14 | 1.5kb | 2024-11-01 20:42:41 | 2024-11-01 20:42:41 |
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];
for(int i=1;i<=n;i++)
cout<<nw[i]<<" ";
cout<<endl;
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: 0
Wrong Answer
time: 0ms
memory: 3940kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
3 0 1 12 5 2 9
result:
wrong answer 1st lines differ - expected: '12', found: '3 0 1 '