QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#726433 | #9528. New Energy Vehicle | ucup-team1412 | WA | 1ms | 5656kb | C++23 | 2.5kb | 2024-11-09 00:27:00 | 2024-11-09 00:27:00 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const ll maxn = 1e5 + 10;
const ll inf = 1e9 + 20;
ll nxt[maxn];
ll a[maxn];
ll nowa[maxn];
struct node {
ll x;
bool operator<(const node& b)const{
return nxt[x] > nxt[b.x];
}
};
struct bat {
ll loc, num;
}b[maxn];
priority_queue<node> pq;
map<ll, queue<ll>> mp;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll t;
cin >> t;
while (t--) {
ll n, m;
cin >> n >> m;
while (!pq.empty()) pq.pop();
mp.clear();
ll nocharge = 0;
for (ll i = 1; i <= n; i++) {
cin >> a[i];
nowa[i] = a[i];
}
for (ll i = 1; i <= m; i++) {
cin >> b[i].loc >> b[i].num;
mp[b[i].num].push(b[i].loc);
}
for (ll i = 1; i <= n; i++) {
mp[i].push(inf);
}
for (ll i = 1; i <= n; i++) {
nxt[i] = mp[i].front();
}
for (ll i = 1; i <= n; i++) {
pq.push({ i });
}
// cout << endl;
// while (!pq.empty()) {
// cout << pq.top().x << ' ';
// pq.pop();
// }
// cout << endl;
ll nowloc = 0;
ll nxtcharge = 1;
while (!pq.empty()) {
ll nowbat = pq.top().x;
if (nowa[nowbat] > b[nxtcharge].loc - nowloc) {
if (nowbat == b[nxtcharge].num) {
mp[nowbat].pop();
nxt[nowbat] = mp[nowbat].front();
pq.pop();
pq.push({nowbat});
}
else {
nowa[nowbat] -= (b[nxtcharge].loc - nowloc);
mp[b[nxtcharge].num].pop();
nxt[b[nxtcharge].num] = mp[b[nxtcharge].num].front();
pq.push({ b[nxtcharge].num });
}
nowloc = b[nxtcharge].loc;
nxtcharge++;
if (nxtcharge > m) {
while (!pq.empty()) {
nowbat = pq.top().x;
nowloc += nowa[nowbat];
pq.pop();
}
}
}
else {
nowloc += nowa[nowbat];
pq.pop();
}
}
cout << nowloc << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5596kb
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: 1ms
memory: 5656kb
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'