QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#687361 | #9528. New Energy Vehicle | wei177 | WA | 17ms | 72200kb | C++17 | 1.5kb | 2024-10-29 18:36:52 | 2024-10-29 18:36:52 |
Judging History
answer
#include <bits/stdc++.h>
#define N 100005
typedef long long ll;
using namespace std;
ll rec[N],sy[N];
deque<ll> idex[N];
const ll inf = 2e18;
void solve()
{
ll n, m;
cin >> n >> m;
ll ans = 0;
for (int i = 1; i <= n; i++) {
cin >> rec[i];
sy[i] = rec[i];
}
priority_queue<pair<ll,ll>,vector<pair<ll, ll>>,greater<pair<ll, ll>> > q;
vector<int> vis(n + 5);
for (int i = 1; i <= m; i++)
{
int x, t;
cin >> x >> t;
if (!vis[t])
{
vis[t] = 1;
q.push({ x,t });
continue;
}
idex[t].push_back(x);
}
for (int i = 1; i <= n; i++){
if (!vis[i])
q.push({ inf,i });
}
while (!q.empty())
{
pair<ll, ll> tmp = q.top();
ll x = tmp.first, id = tmp.second;
q.pop();
if (sy[id] >= x - ans){
ans = x;
sy[id] = rec[id];
}
else
{
ll le = x - ans - sy[id];
ans += sy[id];
while (!q.empty() && le > 0)
{
pair<ll, ll> ttmp = q.top();
ll xx = ttmp.first, iid = ttmp.second;
if (sy[iid] >= le) {
sy[iid] -= le;
ans += le;
le = 0;
}
else {
le -= sy[iid];
ans += sy[iid];
sy[iid] = 0;
q.pop();
}
}
if (le > 0)
break;
}
if(idex[id].empty()) q.push({ inf,id });
else {
q.push({ idex[id].front(),id });
idex[id].pop_front();
}
}
cout << ans << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 17ms
memory: 71720kb
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: 7ms
memory: 72200kb
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 4 13 999999999 2000000000
result:
wrong answer 4th lines differ - expected: '11', found: '13'