QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684219 | #9528. New Energy Vehicle | MCdyc | WA | 0ms | 3792kb | C++23 | 2.0kb | 2024-10-28 11:24:49 | 2024-10-28 11:24:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) a.begin(), a.end()
void solve()
{
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
vector<queue<int>> cnt(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector<pair<int, int>> b(m);
for (int i = 0; i < m; i++)
{
cin >> b[i].first >> b[i].second;
}
b.emplace_back(0, 0);
sort(all(b));
for (int i = 1; i <= m; i++)
{
cnt[b[i].second].push(i);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (int i = 1; i <= n; i++)
{
cnt[i].emplace(0x3f3f3f3f3f3f3f);
q.emplace(cnt[i].front(), i);
cnt[i].pop();
}
auto now = a;
int res = 0;
int tmp = 0;
vector<int> pre(n + 1);
for (int i = 1; i <= m; i++)
{
while (!q.empty() && res < b[i].first)
{
auto [x, y] = q.top();
int p = min(b[i].first - res, now[y]);
res += p;
now[y] -= p;
if (now[y] == 0)
{
q.pop();
}
}
if (res < b[i].first)
{
while (!q.empty())
{
res += now[q.top().second];
now[q.top().second] = 0;
q.pop();
}
cout << res << "\n";
return;
}
if (now[b[i].second] == 0)
{
q.emplace(cnt[b[i].second].front(), b[i].second);
cnt[b[i].second].pop();
}
if (q.top().first == i)
{
q.pop();
q.emplace(cnt[b[i].second].front(), b[i].second);
}
now[b[i].second] = a[b[i].second];
}
cout << res << "\n";
return;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3792kb
input:
2 3 1 3 3 3 8 1 2 2 5 2 1 2 2 1
output:
8 2
result:
wrong answer 1st lines differ - expected: '12', found: '8'