QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#698033 | #9528. New Energy Vehicle | wuyunzhishi | WA | 0ms | 3616kb | C++14 | 1.0kb | 2024-11-01 16:58:51 | 2024-11-01 16:58:52 |
Judging History
answer
#include <bits/stdc++.h>
using ll = long long;
void solve() {
int n, m; std::cin >> n >> m;
std::vector<ll> a(n + 1), x(m + 1, 0), t(m + 1, 0), able(m + 1, 0);
for(int i = 1; i <= n; i++) std::cin >> a[i];
for(int i = 1; i <= m; i++) std::cin >> x[i] >> t[i];
ll need = 0;
for(int i = 1; i <= m; i++) {
ll d = x[i] - x[i - 1];
if(a[t[i]] <= d) {
able[i] = a[t[i]];
need += d - a[t[i]];
}
else {
if(need >= a[t[i]] - d) {
need -= a[t[i]] - d;
able[i] = a[t[i]];
}
else {
able[i] = need + d;
need = 0;
}
}
}
ll sum = 0;
for(int i = 1; i <= n; i++) sum += a[i];
ll ans = 0;
for(int i = 1; i <= m; i++) {
if(sum >= x[i] - x[i - 1]) {
sum -= (x[i] - x[i - 1]);
ans += (x[i] - x[i - 1]);
sum += able[i];
}
else break;
}
ans += sum;
std::cout << ans << '\n';
}
int main()
{
//std::ios::sync_with_stdio(0);
//std::cin.tie(0);
//std::cout.tie(0);
int t = 1;
std::cin >> t;
while(t--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3592kb
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: 3616kb
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:
10 11 4 11 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '10'