QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685839 | #9528. New Energy Vehicle | blhxzjr# | WA | 2ms | 9728kb | C++23 | 1.5kb | 2024-10-28 21:32:13 | 2024-10-28 21:32:20 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int,int>;
const int N=1e6+10;
int n,m,_;
int a[N];
PII b[N],d[N];
vector<int> g[N];
int c[N];
void solve(){
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
cin >> b[i].first >> b[i].second;
}
sort(b + 1,b + 1 + m);
for (int i =1 ; i <= m; i++) {
d[i].first = b[i].first;
if (g[b[i].second].empty()) {
d[i].second = a[b[i].second];
}
g[b[i].second].push_back(i);
}
for (int i = 1; i <= n; i++) {
if (g[i].empty()) {
d[m + 1].second += a[i];
}
g[i].push_back(m + 1);
}
int l = 1;
int pre = 0;
for (int i = 1; i <= m; i++) {
while (l <= m + 1) {
if (d[l].second < d[i].first - pre) {
// cout << d[l].second << endl;
pre += d[l].second;
d[l].second = 0;
}
else {
d[l].second -= d[i].first - pre;
break;
}
l++;
}
if (l > m + 1) break;
pre = d[i].first;
// cout << pre << " " << l << " " << d[l].second << endl;
int now = b[i].second;
c[now]++;
d[g[now][c[now]]].second += a[now];
// cout << pre << " " << l << " " << d[l].second << endl;
}
pre += d[m + 1].second;
cout << pre << endl;
}
void clear(){
for (int i = 0; i <= max(n,m) + 2; i++) {
a[i] = 0;
g[i].clear();
c[i] = 0;
b[i].first = b[i].second = d[i].first = d[i].second = 0;
}
}
signed main(){
ios_base::sync_with_stdio(false),cin.tie(0);
_=1;
cin >> _;
while(_--){
solve();
clear();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9728kb
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: 2ms
memory: 9720kb
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 12 4 12 999999999 2000000000
result:
wrong answer 1st lines differ - expected: '9', found: '6'