QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#750792 | #9528. New Energy Vehicle | Tmonkey | WA | 1ms | 7892kb | C++20 | 1.6kb | 2024-11-15 15:59:17 | 2024-11-15 15:59:17 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 1e5;
int T = 1;
int n, m;
ll a[N + 5], b[N + 5];
ll now[N + 5], pos[N + 5];
vector<int> g[N + 5];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
now[i] = a[i];
g[i].clear();
}
priority_queue<pii, vector<pii>, greater<pii>> q;
for (int i = 1; i <= m; i++)
{
cin >> b[i] >> pos[i];
g[pos[i]].push_back(i);
q.push({i, pos[i]});
}
ll sum = 0, cur = 0;
for (int i = 1; i <= n; i++)
{
if (g[i].empty())
{
sum += a[i];
now[i] = 0;
}
}
for (int i = 1; i <= m; i++)
{
while (!q.empty() && cur < b[i])
{
int p = q.top().second;
q.pop();
if (now[p] < b[i] - cur)
{
cur += now[p];
now[p] = 0;
}
else
{
now[p] -= b[i] - cur;
cur += b[i] - cur;
}
}
if (sum < b[i] - cur)
break;
sum -= b[i] - cur;
cur += b[i] - cur;
auto it = upper_bound(g[pos[i]].begin(), g[pos[i]].end(), i);
if (it == g[pos[i]].end())
sum += a[pos[i]];
else
{
if ((*it) < q.top().first)
q.push({(*it), pos[i]});
now[pos[i]] = a[pos[i]];
}
}
cout << cur + sum << '\n';
}
int main()
{
cin >> T;
while (T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7892kb
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: 5824kb
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 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'