QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685656 | #9528. New Energy Vehicle | yxd# | RE | 0ms | 0kb | C++14 | 1.4kb | 2024-10-28 20:39:32 | 2024-10-28 20:39:33 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+10;
pair<int,int> a[N];
int b[N],c[N];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>b[i];
c[i]=b[i];
}
for(int i=1;i<=m;i++){
cin>>a[i].first>>a[i].second;
}
sort(a+1,a+m+1);
int res=0,pre=1,idx=0;
for(int i=1;i<=m;i++){
if(a[i].first>b[a[i].second]){
res+=b[a[i].second];
idx+=b[a[i].second];
b[a[i].second]=0;
}else{
res+=a[i].first-idx;
idx=a[i].first;
}
while(idx>=a[pre].first){
b[a[pre].second]=c[a[pre].second];
pre++;
}
}
for(int i=1;i<=n;i++){
if(b[i]){
idx+=b[i];
}else{
continue;
}
while(idx>=a[pre].first){
b[a[pre].second]=c[a[pre].second];
pre++;
if(pre>m)break;
}
}
for(int i=1;i<=n;i++){
res+=b[i];
}
cout<<res<<"\n";
}
}
详细
Test #1:
score: 0
Runtime Error
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1