QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#701626 | #9528. New Energy Vehicle | Forever_Young# | WA | 0ms | 16172kb | C++14 | 1.7kb | 2024-11-02 14:27:26 | 2024-11-02 14:27:27 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define N 1000005
using namespace std;
int n,m;
ll full_a[N],a[N],x[N];
int last[N],fst[N],nxt[N],t[N];
void work(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++){
scanf("%d",&full_a[i]);
a[i]=full_a[i];
last[i]=0;
fst[i]=0;
}
for (int i=1;i<=m;i++){
scanf("%d%d",&x[i],&t[i]);
if (!fst[t[i]]) fst[t[i]]=i;
nxt[last[t[i]]]=i;
last[t[i]]=i;
}
// for (int i=1;i<=m;i++) printf("%d",nxt[i]); puts("");
// for (int i=1;i<=n;i++) printf("%d",fst[i]); puts("");
ll no_charge = 0;
ll now_len=0,now_dp=1;
set<int>st;
for (int i=1;i<=n;i++) if (fst[i]==0) no_charge+=a[i]; else st.insert(fst[i]);
for (int i=1;i<=m;i++){
while(now_len<x[i]){
if (!st.empty()){
int j = t[*st.begin()];
ll mv_len = min(x[i]-now_len,a[j]);
now_len+=mv_len;
a[j]-=mv_len;
if (a[j]==0) st.erase(st.begin());
} else{
ll mv_len = min(x[i]-now_len,no_charge);
now_len+=mv_len;
no_charge-=mv_len;
break;
}
}
// printf("%lld %lld\n",now_len,no_charge);
if (st.find(i)!=st.end()) st.erase(i);
if (now_len==x[i]){
if (nxt[i]){
st.insert(nxt[i]);
a[t[i]]=full_a[t[i]];
} else{
no_charge+=full_a[t[i]];
}
} else break;
}
printf("%lld\n",now_len+no_charge);
}
int main(){
int T;
scanf("%d",&T);
while(T--) work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 16172kb
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: 16108kb
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 5 4 9 999999999 1000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '5'