QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#752657 | #9528. New Energy Vehicle | Tmonkey | WA | 1ms | 5892kb | C++20 | 2.2kb | 2024-11-16 09:05:16 | 2024-11-16 09:05:18 |
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;
}
}
int ma = 0;
for (int i = 1; i <= m; i++)
{
while (!q.empty() && cur < b[i])
{
int p = q.top().second;
int num = q.top().first;
ma = max(ma, num);
// cout << num << ' ' << p << '\n';
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 (now[p] > 0 && num > i)
q.push({num, p});
}
}
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]];
now[pos[i]] = 0;
}
else
{
if ((*it) < ma)
{
q.push({(*it), pos[i]});
// cout << (*it) << ' ' << pos[i] << '\n';
}
now[pos[i]] = a[pos[i]];
// cout << "YES\n";
}
// cout << sum << '\n';
// for (int j = 1; j <= n; j++)
// {
// cout << now[j] << ' ';
// }
// cout << '\n';
}
// cout << cur << ' ' << sum << '\n';
cout << cur + sum << '\n';
}
int main()
{
cin >> T;
while (T--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5640kb
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: 5892kb
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'