QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#681868 | #9528. New Energy Vehicle | qianchen06 | WA | 1ms | 3812kb | C++14 | 1.8kb | 2024-10-27 12:32:06 | 2024-10-27 12:32:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m;
const int inf = 1e9 + 10;
const int maxn = 1e5 + 10;
int a[maxn];
vector<queue<int>> vec;
int x[maxn];
int t[maxn];
void solve()
{
cin >> n >> m;
vec.resize(n + 1);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
for (int i = 1; i <= m; i++)
{
cin >> x[i] >> t[i];
vec[t[i]].push(x[i]);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
for (int i = 1; i <= n; i++)
{
if (vec[i].size())
{
q.push({vec[i].front(), a[i]});
vec[i].pop();
}
else
{
q.push({inf, a[i]});
// vis[i] = 1;
}
}
int j = 1;
int ans = 0;
while (q.size() && j <= m)
{
auto ft = q.top();
q.pop();
if (ans + ft.second >= x[j])
{
ft.second -= x[j] - ans;
ans = x[j];
if (ft.second && ft.first != x[j])
{
q.push(ft);
}
if (vec[t[j]].size())
{
q.push({vec[t[j]].front(), a[t[j]]});
vec[t[j]].pop();
}
else
{
q.push({inf, a[t[j]]});
// vis[t[j]] = 1;
}
j++;
}
else
{
ans += ft.second;
}
}
while (q.size())
{
auto ft = q.top();
q.pop();
ans += ft.second;
}
cout << ans << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
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: 3596kb
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 12 999999999 2000000000
result:
wrong answer 4th lines differ - expected: '11', found: '12'