QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#742927 | #9528. New Energy Vehicle | can_no_do_dp | WA | 1ms | 6136kb | C++14 | 1.0kb | 2024-11-13 17:39:34 | 2024-11-13 17:39:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define int long long
int t,n,m,sum,vis[100005],a[100005],b[100005],c[100005],a1[100005];
signed main(){
cin>>t;
while(t--){
memset(vis,0,sizeof(vis));
int could=0;
sum=0;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
a1[i]=a[i];
}
for(int i=1;i<=m;i++){
cin>>b[i]>>c[i];
b[i]=b[i]-b[i-1];
vis[c[i]]=i;
}
for(int i=1;i<=n;i++){
if(vis[i]==0)could+=a[i];
}
for(int i=1;i<=m;i++){
a[i]=a1[i];
int j=i+1;
if(a[i]>=b[i]){
sum+=b[i];
b[i]=0;
}
else{
b[i]-=a[i];
sum+=a[i];
a[i]=0;
while(j<=m&&b[i]){
if(b[i]>=a[j]){
sum+=a[j];
b[i]-=a[j];
a[j]=0;
j++;
}
else{
sum+=b[i];
b[i]=0;
a[j]-=b[i];
}
}
}
sum+=min(could,b[i]);
could-=min(could,b[i]);
if(could<=0&&j>m)break;
a[i]=a1[i];
if(vis[c[i]]==i)could+=a[i];
}
cout<<sum+max(could,(int)0)<<endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 6136kb
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: 5720kb
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:
11 11 11 11 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '11'