QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685294 | #9528. New Energy Vehicle | Y_J_Y# | TL | 0ms | 0kb | C++20 | 1.6kb | 2024-10-28 18:43:52 | 2024-10-28 18:43:53 |
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;
void up(int t,int now)
{
while(q[t].size()&&q[t].front()<=now) q[t].pop();
if(q[t].size()) hp.push((qw){t,q[t].front()});
else if(a[t]) hp.push((qw){t,m+1});
}
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();
up(t,now);
}
if(place<x[now+1]) return place;
now++;
a[T[now]]=st[T[now]];
hp.pop();
up(T[now],now);
//for(auto w:hp) cout<<w.x<<" "<<w.y<<endl;
}
//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
3 5
2 2 3
1 1
3 2
6 3
7 2
8 3
*/
詳細信息
Test #1:
score: 0
Time Limit Exceeded
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1