QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#687732 | #9528. New Energy Vehicle | xunxxxx | WA | 1ms | 7880kb | C++23 | 1.3kb | 2024-10-29 20:54:37 | 2024-10-29 20:54:38 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define N 100010
int n,m;
int a[N],x[N],t[N],o[N];
int f[N];
vector<int>g[N];
void solve()
{
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i],o[i]=a[i],g[i].clear();
for(int i=1;i<=m;i++)
{
cin>>x[i]>>t[i];
g[t[i]].push_back(i);//id¿ÉÒÔÔÚµÚ¼¸¸öλÖóäµç
}
int s=0;//½ô¼±Çé¿öÏÂÓõ磬²»¿É³äµÄµç
for(int i=1;i<=n;i++) if(!g[i].size()) s+=a[i],a[i]=0;
priority_queue<int,vector<int>,greater<int>>q;
for(int i=1;i<=m;i++) q.push(i);
for(int i=1;i<=m;i++)
{
int d=a[i]-a[i-1];
while(d>0&&!q.empty())
{
int u=q.top();
q.pop();
if(u<i) continue;
int id=t[u];
int t=min(a[id],d);
d-=t;
a[id]-=t;
if(a[id]>0) q.push(u);
}
if(d>0)
{
int t=min(d,s);
s-=t;
d-=t;
if(d>0)
{
cout<<a[i]-d<<"\n";
return ;
}
}
a[t[i]]=o[t[i]];
auto j=upper_bound(g[t[i]].begin(),g[t[i]].end(),i);
if(j!=g[t[i]].end()) q.push(*j);
}
int ans=s+a[m];
for(int i=1;i<=n;i++) ans+=a[i];
cout<<ans<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int T=1;
cin>>T;
while(T--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7880kb
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: 7880kb
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 1999999998 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'