QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685151 | #9528. New Energy Vehicle | rrt517 | WA | 1ms | 9924kb | C++23 | 1.3kb | 2024-10-28 17:56:16 | 2024-10-28 17:56:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1000010,mod=1e9+7,eps=1e-9;
int a[N],x[N],tt[N],b[N];
int n,m;
void solve(){
int n,m;
cin>>n>>m;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>q;
vector<vector<int>>ty(n+10);
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
q.push({m+1,i});
}
for(int i=1;i<=m;i++){
cin>>x[i]>>tt[i];
ty[tt[i]].push_back(i);
q.push({x[i],tt[i]});
}
for(int i=1;i<=n;i++){
ty[i].push_back(m+1);
}
int now=0;
for(int i=1;i<=m;i++){
while(q.size() && q.top().first<i) q.pop();
while(q.size() && now<x[i]){
auto t=q.top();
q.pop();
int tmp=min(x[i]-now,a[t.second]);
now+=tmp;
a[t.second]-=tmp;
if(a[t.second]){
q.push(t);
}
}
if(now<x[i]){
cout<<now<<"\n";
return ;
}
a[tt[i]]=b[tt[i]];
int pos=upper_bound(ty[tt[i]].begin(),ty[tt[i]].end(),i)-ty[tt[i]].begin();
q.push({ty[tt[i]][pos],tt[i]});
// for(int i=1;i<=n;i++){
// cout<<a[i]<<" ";
// }
// cout<<"\n";
}
for(int i=1;i<=n;i++){
now+=a[i];
}
cout<<now<<"\n";
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
cin>>t;
while(t--){
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9924kb
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: 9760kb
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 9 4 9 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '9'