QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#690095 | #9528. New Energy Vehicle | yangrun | WA | 4ms | 34992kb | C++17 | 1.7kb | 2024-10-30 20:14:37 | 2024-10-30 20:14:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<long long, long long>
int read() {
int res = 0, flg = 1;
char c = getchar();
while(!isdigit(c)) {
if(c == '-') flg = 0;
c = getchar();
}
while(isdigit(c)) {
res = (res << 3) + (res << 1) + (c ^ 48);
c = getchar();
}
return flg ? res : -res;
}
const int N = 1e6 + 10, inf = 0x3f3f3f3f3f3f3f3f;
int T, n, m, ans, res, mx;
int a[N], x[N], y[N], loc[N], aa[N];
vector<int> v[N];
priority_queue<pii, vector<pii>, greater<pii> > q;
void addq(int id) {
if(loc[id] < v[id].size()) {
q.push({v[id][loc[id]], id});
loc[id]++;
} else {
q.push({inf, id});
}
}
void solve() {
n = read(), m = read();
res = 0;
for (int i = 1; i <= n; i++) {
aa[i] = a[i] = read();
}
for (int i = 1; i <= m; i++) {
x[i] = read(), y[i] = read();
v[y[i]].push_back(x[i]);
}
for(int i = 1; i <= n; i++) {
addq(i);
}
int now, w;
for(int i = 1; i <= m; ++i) {
while(q.size() && res < x[i]) {
while(q.size() && q.top().first < x[i]) {
if(a[q.top().second]) addq(q.top().second);
q.pop();
}
if(!q.size()) break;
now = q.top().second;
w = min(a[now], x[i] - res);
a[now] -= w;
res += w;
if(!a[now]) q.pop();
}
if(res < x[i]) {
cout << res << '\n';
return;
}
if(a[y[i]] == 0) addq(y[i]);
a[y[i]] = aa[i];
}
while(q.size()) q.pop();
for(int i = 1; i <= n; ++i) {
res += a[i];
v[i].clear();
}
cout << res << '\n';
}
signed main() {
T = read();
while (T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 33840kb
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: 4ms
memory: 34992kb
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 9 4 11 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '9'