QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#684411 | #9528. New Energy Vehicle | ihavebigdick | WA | 0ms | 3584kb | C++14 | 1.4kb | 2024-10-28 13:13:03 | 2024-10-28 13:13:04 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
#define int long long
using PII = std::pair<int, int>;
const int N = 1e5+10, INF = 1e9+10;
void solve()
{
int n, m; std::cin >> n >> m;
std::vector<int> a(n+1), enr(n+1);
std::vector<std::vector<int>> chr(n+1);
std::vector<int> pos(m+1);
std::vector<int> idx(m+1);
std::vector<int> b(m+1);
for(int i = 1; i <= n; i ++ )
{
std::cin >> a[i];
enr[i] = a[i];
}
for(int i = 1; i <= m; i ++ )
{
std::cin >> pos[i] >> b[i];
chr[b[i]].emplace_back(pos[i]);
}
std::priority_queue<PII, std::vector<PII>, std::greater<PII> > hp;
for(int i = 1; i <= n; i ++ )
{
chr[i].emplace_back(INF);
hp.emplace(chr[i][0], i);
}
int ans = 0;
for(int i = 1; i <= m; i ++ )
{
int d = pos[i]-pos[i-1];
while(hp.size())
{
auto [x, t] = hp.top();
int cost = std::min(d, enr[t]);
enr[t] -= cost;
d -= cost;
ans += cost;
if(!enr[t]) hp.pop();
if(!d) break;
}
if(!d)
{
int t = b[i];
if(hp.size() && hp.top().y == t)
hp.pop();
enr[t] = a[t];
hp.emplace(enr[t], t);
}
// for(int x: enr)
// std::cout << x << ' ';
// std::cout << '\n';
}
for(int& x: enr)
ans += x;
std::cout << ans << '\n';
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t; std::cin >> t;
while(t -- )
{
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 0ms
memory: 3584kb
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 9 4 9 999999999 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '9'