QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685248 | #9528. New Energy Vehicle | Y_J_Y# | TL | 11ms | 140696kb | C++20 | 1.9kb | 2024-10-28 18:29:36 | 2024-10-28 18:29:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,M=2e5+5;
typedef long long ll;
queue<int> q[N];
int a[N],st[N];
struct qw{
int t,pla;
bool operator <(const qw&b)const
{
return pla>b.pla;
}
};
priority_queue<qw> hp;
int x[M],T[M];
int n,m;
ll sol()
{
for(int i=1;i<=n;i++) hp.push((qw){i,q[i].front()});
x[0]=0;
int now=0,t;
ll place=0;
while(now<m)
{
//now - now+1 place x[now+1]
while(place<x[now+1]&&hp.size())
{
t=hp.top().t;
// cout<<place<<" "<<t<<" "<<a[t]<<endl;
if(a[t]+place<=x[now+1])
{
place+=a[t];
a[t]=0;
}
else
{
a[t]-=x[now+1]-place;
place=x[now+1];
}
hp.pop();
if(q[t].size()) q[t].pop();
if(q[t].size()) hp.push((qw){t,q[t].front()});
else hp.push((qw){t,m+1});
}
if(place<x[now+1]) return place;
now++;
a[T[now]]=st[T[now]];
}
//now=m+1,剩下的全用
ll res=x[m];
while(hp.size())
{
res+=a[hp.top().t];
a[hp.top().t]=0;
hp.pop();
}
return res;
}
#define endl '\n'
int main()
{
cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
int TT;
cin>>TT;
while(TT--)
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i],st[i]=a[i];
x[m+1]=1e9+10;
for(int i=1;i<=m;i++)
{
cin>>x[i]>>T[i];
q[T[i]].push(i);
}
for(int i=1;i<=n;i++) q[i].push(m+1);
cout<<sol()<<endl;
for(int i=1;i<=n;i++)
while(q[i].size()) q[i].pop();
while(hp.size()) hp.pop();
}
return 0;
}
/*
1
5 3
1 2 4 3 2
1 1
4 3
7 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 140696kb
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