QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685049 | #9528. New Energy Vehicle | Y_J_Y# | WA | 1ms | 7720kb | C++20 | 1.1kb | 2024-10-28 17:18:46 | 2024-10-28 17:18:46 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define root 1,n,1
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define pd __gnu_pbds
inline ll read() {
ll x=0,w=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
inline void print(__int128 x){
if(x<0) {putchar('-');x=-x;}
if(x>9) print(x/10);
putchar(x%10+'0');
}
#define maxn 1000010
#define int long long
const double eps=1e-8;
#define int_INF 0x3f3f3f3f
#define ll_INF 0x3f3f3f3f3f3f3f3f
int a[maxn];int x[maxn];int t[maxn];
signed main() {
int T=read();
while(T--) {
int n=read();int m=read();
int cnt=0;
for(int i=1;i<=n;i++) {
a[i]=read();
cnt+=a[i];
}
for(int i=1;i<=m;i++) {
x[i]=read();t[i]=read();
}
m++;
x[m]=1e18;
int sum=0;int ans=-1;
for(int i=1;i<=m;i++) {
if(x[i]>cnt+sum) {
ans=cnt+sum;
break;
}
if(sum+a[t[i]]>x[i]) {
sum=x[i];
}
else {
sum+=a[t[i]];
}
// cout<<i<<","<<sum<<endl;
}
cout<<ans<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7696kb
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: 7720kb
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:
10 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'