QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875403 | #9528. New Energy Vehicle | Mini_PEKKA | WA | 0ms | 7908kb | C++20 | 1.2kb | 2025-01-29 17:56:12 | 2025-01-29 17:56:13 |
Judging History
answer
#include <bits/stdc++.h>
#define se second
#define pb push_back
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
constexpr ll N = 100010;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
ll n, m, a[N], x[N], t[N], _a[N];
vector<ll> p[N];
ll find(ll t, ll x) {
return *upper_bound(p[t].begin(), p[t].end(), x);
}
void solve() {
cin >> n >> m;
rep(i, 1, n) {
cin >> a[i];
_a[i] = a[i];
p[i].clear();
}
rep(i, 1, m) {
cin >> x[i] >> t[i];
p[t[i]].pb(x[i]);
}
rep(i, 1, n) {
p[i].pb(inf);
}
ll cur = 0;
set<pll> bat;
rep(i, 1, n) {
bat.insert({find(i, cur), i});
}
x[m + 1] = inf;
ll i = 1;
while (1) {
if (bat.empty()) {
cout << cur << '\n';
break;
}
ll tp = bat.begin()->se;
bat.erase(bat.begin());
if (a[tp] > x[i] - cur) {
a[tp] -= x[i] - cur;
cur = x[i];
bat.insert({find(tp, cur), tp});
bat.insert({find(t[i], cur), t[i]});
a[t[i]] = _a[t[i]];
i++;
} else {
cur += a[tp];
a[tp] = 0;
}
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
ll t;
cin >> t;
rep(i, 1, t) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7908kb
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: 5868kb
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:
6 11 4 11 999999999 1000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'