QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#704686 | #9528. New Energy Vehicle | fosov | RE | 0ms | 3528kb | C++14 | 1.8kb | 2024-11-02 20:37:14 | 2024-11-02 20:37:16 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ull unsigned long long
#define MOD ((int) (1e9) + 7)
#define pii pair<int, int>
#define inf 0x7fffffff
#define N 100010
int fr[N], pre[N], nxt[N], A[N], a[N];
pii xs[N];
int main() {
#ifdef TEST
freopen("zz.in", "r+", stdin);
#endif
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t; cin >> t;
while (t --) {
int n, m; cin >> n >> m;
for (int i = 1; i <= n; ++ i) {
cin >> A[i];
a[i] = A[i];
fr[i] = inf;
}
for (int i = 1; i <= m; ++ i) {
cin >> xs[i].first >> xs[i].second;
}
for (int i = m; i >= 1; -- i) {
auto& [x, bt] = xs[i];
nxt[x] = fr[bt];
fr[bt] = x;
}
set<pii> ord;
for (int i = 1; i <= n; ++ i) {
pre[i] = fr[i];
ord.insert(pii(fr[i], i));
}
ll dst = 0;
for (int i = 1; i <= m; ++ i) {
auto [x, bt] = xs[i];
int dx = x - xs[i-1].first;
while (!ord.empty() && a[ord.begin()->second] <= dx) {
dx -= a[ord.begin()->second];
dst += a[ord.begin()->second];
a[ord.begin()->second] = 0;
ord.erase(ord.begin());
}
if (dx && ord.empty()) break;
a[ord.begin()->second] -= dx, dst += dx;
a[bt] = A[bt];
if (ord.count(pii(pre[bt], bt))) ord.erase(ord.find(pii(pre[bt], bt)));
ord.insert(pii(nxt[pre[bt]], bt)), pre[bt] = nxt[pre[bt]];
}
for (int i = 1; i <= n; ++ i) dst += a[i];
cout << dst << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
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
Runtime Error
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