QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#683280 | #9528. New Energy Vehicle | 42m0rr0w | WA | 0ms | 17864kb | C++20 | 1.6kb | 2024-10-27 19:51:52 | 2024-10-27 19:51:52 |
Judging History
answer
#include <bits/stdc++.h>
#define test(x) cout<<#x<<" = "<<x<<endl
#define endl '\n'
#define int long long
using namespace std;
const int MAXN = 1e6 + 100, MAX = 1e18;
int n, m;
string s;
int a[MAXN], lst[MAXN], nxt[MAXN], vis[MAXN], ma[MAXN], fst[MAXN], p[MAXN], t[MAXN];
void solve() {
cin >> n >> m;
int sum = 0;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
ma[i] = a[i];
lst[i] = 0;
}
for (int i = 1; i <= n; ++i) {
fst[i] = MAX;
vis[i] = 0;
}
for (int i = 1; i <= m; ++i) {
cin >> p[i] >> t[i];
nxt[lst[t[i]]] = i;
lst[t[i]] = i;
fst[t[i]] = min(fst[t[i]], i);
}
for (int i = 1; i <= n; ++i)
nxt[lst[i]] = MAX;
set<pair<int, int>> q;
for (int i = 1; i <= n; ++i) {
q.insert({fst[i], i});
vis[i] = fst[i];
}
for (int i = 1; i <= m; ++i) {
for (int i = 1; i <= n; ++i)
cout << a[i] << " \n"[i == n];
int d = p[i] - p[i - 1];
while (!q.empty()) {
auto [pos, id] = *q.begin();
if (a[id] > d) {
a[id] -= d;
d = 0;
break;
} else {
d -= a[id];
a[id] = 0;
q.erase({pos, id});
vis[id] = 0;
}
}
if (d > 0) {
cout << p[i] - d << endl;
return ;
}
a[t[i]] = ma[t[i]];
q.erase({vis[t[i]], t[i]});
cout << nxt[i] << ' ' << t[i] << endl;
q.insert({nxt[i], t[i]});
vis[t[i]] = nxt[i];
}
sum = 0;
for (int i = 1; i <= n; ++i) {
cout << a[i] << " \n"[i == n];
sum += max(0ll, a[i]);
}
test(sum);
cout << p[m] + sum << endl;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
cin >> tt;
while (tt--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 17864kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
3 3 3 1000000000000000000 1 3 0 1 sum = 4 12 5 2 1000000000000000000 2 5 2 1000000000000000000 1 5 2 sum = 7 9
result:
wrong answer 1st lines differ - expected: '12', found: '3 3 3'