QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#703910 | #9528. New Energy Vehicle | DFLMKWR | WA | 0ms | 3844kb | C++20 | 2.1kb | 2024-11-02 18:51:11 | 2024-11-02 18:51:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define dbg(x) cout << #x << " = " << (x) << "\n"
#define MULTI int _; cin >> _; while (_--)
const int N = 1e6 + 5, INF = 0x3f3f3f3f3f3f3f3f;
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n + 1), c(n + 1);
vector<array<int, 2>> b(m + 2);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
vector<vector<int>> v(n + 1);
for (int i = 1; i <= m; i++) {
cin >> b[i][0] >> b[i][1];
v[b[i][1]].push_back(b[i][0]);
}
set<array<int, 2>> se;
for (int i = 1; i <= n; i++) {
v[i].push_back(INF);
se.insert({v[i][0], i});
c[i] = a[i];
v[i].erase(v[i].begin());
}
for (int i = 1; i <= m; i++) {
int t = b[i][0] - b[i - 1][0];
while (t) {
// dbg(t);
// dbg(c[1]);
// dbg(c[2]);
if (se.size() == 0) {
// dbg("BBBBB");
int ans = b[i - 1][0];
// dbg(i);
int tmp = 0;
for (int j = 1; j <= n; j++) {
tmp += c[j];
}
if (tmp == 0) {
ans = b[i][0];
}
cout << ans << "\n";
return;
}
int u = (*se.begin())[1];
// for (auto it : se) {
// dbg(it[0]);
// dbg(it[1]);
// }
// dbg((*se.begin())[0]);
// dbg(b[i][0]);
if ((*se.begin())[0] < b[i][0]) {
se.erase(se.begin());
u = (*se.begin())[1];
}
// dbg(u);
if (t > c[u]) {
t -= c[u];
c[u] = 0;
se.erase(se.begin());
} else {
c[u] -= t;
t = 0;
}
//
// dbg(c[1]);
// dbg(c[2]);
}
int u = b[i][1];
if (v[u].size()) {
se.insert({v[u][0], u});
c[u] = a[u];
v[u].erase(v[u].begin());
}
}
// dbg("AAAAA");
if (se.size()) {
for (auto it : se) {
if (it[0] == INF) continue;
c[it[1]] = a[it[1]];
}
int ans = b[m][0];
for (int j = 1; j <= n; j++) {
ans += c[j];
// dbg(c[j]);
}
cout << ans << "\n";
}
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
1
3 2
1 100 100
201 1
202 3
1
3 2
100 100 100
250 2
252 2
*/
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
MULTI solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3844kb
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: 3648kb
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 11 5 11 1000000000 2000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '5'