QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#694842 | #9528. New Energy Vehicle | xiey# | WA | 0ms | 3616kb | C++20 | 2.0kb | 2024-10-31 18:46:59 | 2024-10-31 18:47:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define int long long
#define endl '\n'
const int N = 1e5 + 10;
void run()
{
map<int, int> mp;
int n, m;
cin >> n >> m;
int a[n + 1] = {}, b[n + 1] = {}, st[n + 1] = {};
int sum = 0;
for (int i = 0; i < n; i++)
{
cin >> a[i];
b[i] = a[i];
}
vector<PII> p;
for (int i = 0; i < m; i++)
{
int x, t;
cin >> x >> t;
p.push_back({x, t});
st[t] = 1;
mp[t] += 1;
}
for (int i = 0; i < n; i++)
if (st[i] == 0)
sum += a[i];
int ls = 0;
int prev = 0;
int ans = 0;
for (int i = 0; i < m; i++)
{
int dis = p[i].first - prev;
for (int j = ls; j < m; j++)
{
if (a[p[j].second] >= dis)
{
a[p[j].second] -= dis;
dis = 0;
ls = j;
mp[p[j].second] -= 1;
break;
}
else
{
dis -= a[p[j].second];
a[p[j].second] = 0;
ls = j;
mp[p[j].second] -= 1;
}
}
if (dis)
{
if (sum >= dis)
{
sum -= dis;
dis = 0;
}
else
{
dis -= sum;
sum = 0;
}
}
ans = ans + (p[i].first - prev) - dis;
prev = p[i].first;
a[p[i].second] = b[p[i].second];
// cout << sum << endl;
if (mp[p[i].second] <= 0 && st[p[i].second] == 1)
{
sum += b[p[i].second];
st[p[i].second] = 0;
}
}
ans += sum;
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
cin >> tt;
while (tt--)
run();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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:
9 11 8 11 999999999 1000000000
result:
wrong answer 3rd lines differ - expected: '4', found: '8'