QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698526 | #9528. New Energy Vehicle | Vareal | WA | 1ms | 8024kb | C++17 | 2.0kb | 2024-11-01 20:11:18 | 2024-11-01 20:11:18 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <bitset>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <cassert>
#include <random>
#include <chrono>
#include <ctime>
#include <cstdlib>
#define pii pair<int,int>
#define mp make_pair
#define pb emplace_back
#define debug() cout<<"qwq"<<endl
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned long long ull;
const int DMAX = 200000 + 5;
const double INF = 1e9;
const int MOD = 998244353;
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
template<class T> inline void read(T &x){
T f=1; x=0; char ch=getchar();
while(ch<'0' || ch>'9'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch<='9' && ch>='0'){ x=x*10+ch-'0';ch=getchar(); }
x*=f;
}
int T;
int a[DMAX], real[DMAX];
int n, m;
int x[DMAX], t[DMAX];
int b[DMAX], cnt;
int las[DMAX];
void solve(){
cnt = 0;
read(n), read(m);
for(int i = 1; i <= n; i++) read(a[i]), real[i] = a[i], las[i] = -1;
for(int i = 1; i <= m; i++) read(x[i]), read(t[i]), b[++ cnt] = t[i], las[t[i]] = i;
for(int i = 1; i <= n; i++) if(las[i] == -1) b[++ cnt] = i, las[i] = cnt;
ll now = 0;
int p = 1;
bool flag = 1;
for(int i = 1; i <= m; i++){
ll diff = x[i] - now;
while(p <= cnt){
if(diff > real[b[p]]){
diff -= real[b[p]];
now += real[b[p]];
real[b[p]] = 0;
p ++;
}
else{
real[b[p]] -= diff;
now += diff;
diff = 0;
break;
}
}
if(diff){
flag = 0;
break;
}
real[t[i]] = a[t[i]];
if(las[t[i]] < p){
b[++ cnt] = t[i], las[t[i]] = cnt;
}
if(p == i){
p ++;
}
}
if(!flag){
printf("%lld\n", now);
return ;
}
//cout<<now<<endl;
for(int i = 1; i <= n; i++){
now += real[i];
}
printf("%lld\n", now);
return ;
}
int main(){
read(T);
while(T --){
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8024kb
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: 5912kb
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 5 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '5'