QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#725421 | #9528. New Energy Vehicle | P3KO | TL | 8ms | 73496kb | C++20 | 1.2kb | 2024-11-08 17:37:21 | 2024-11-08 17:37:21 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
ll n,m,a[MAXN],x[MAXN],t[MAXN];
ll cur[MAXN],res;
queue<int>q[MAXN];
void input(){
res=0;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
res+=a[i];
cur[i]=a[i];
while(!q[i].empty())q[i].pop();
}
for(int i=1;i<=m;i++){
cin>>x[i]>>t[i];
q[t[i]].push(i);
}
}
void output(){
cout<<res<<"\n";
}
void solve(){
input();
ll tmp=res;
priority_queue<pair<int,int>>pq;
for(int i=1;i<=n;i++)
if(!q[i].empty())
pq.push({-q[i].front(),i});
else
pq.push({-m-1,i});
for(int i=1;i<=m;i++){
ll d=x[i]-x[i-1];
if(d<=tmp){
tmp-=d;
while(d){
int val=-pq.top().first,tag=pq.top().second;
pq.pop();
if(d>=cur[tag])
d-=cur[tag],cur[tag]=0;
else{
cur[tag]-=d,d=0;
if(val>i)pq.push({-val,tag});
}
}
tmp+=a[t[i]]-cur[t[i]],res+=a[t[i]]-cur[t[i]],cur[t[i]]=a[t[i]];
q[t[i]].pop();
if(!q[t[i]].empty())pq.push({-q[t[i]].front(),t[i]});
}else break;
}
output();
}
int main(){
int t;cin>>t;
while(t--){
solve();
}
}
/*
6
3 2
2 2 2
6 1
7 1
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 8ms
memory: 73496kb
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:
9