QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#685924 | #9528. New Energy Vehicle | 202200810234 | TL | 0ms | 3608kb | C++14 | 2.0kb | 2024-10-28 21:58:05 | 2024-10-28 21:58:05 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
#define rep(i, o, p) for(int i = o; i <= p; i ++ )
using namespace std;
typedef long long ll;
constexpr int maxn = 1e5+10;
const ll INF = 1e16;
void sol(){
int n, m;
cin >> n >> m;
vector <ll> a(n + 5), pos(m + 5), c(m + 5), t(n + 5);
map <ll, ll> mp, list;
vector<ll> tmp(n + 5);
set <ll> s;
rep(i, 1, n) {
cin >> a[i];
t[i] = a[i];
}
rep(i, 1, m) {
cin >> pos[i] >> c[i];
mp[pos[i]] = c[i]; // pos x has y
if(tmp[c[i]]) list[tmp[c[i]]] = pos[i];
else s.insert(pos[i]);
tmp[c[i]] = pos[i];
}
rep(i, 1, n) {
if(!tmp[i]) s.insert(INF + i);
mp[INF + i] = i;
}
long long ans = 0;
rep(i, 1, m){
while(*s.begin() < pos[i]) {
int a = *s.begin();
s.erase(s.begin());
if(list[a])
s.insert(list[a]);
}
ll l = pos[i] - pos[i - 1];
ll cnt = 0;
auto it = *s.begin();
bool flag = 1;
while(1){
//cout << 73;
if(t[mp[it]] >= l ) {
// cout << mp[it] << endl;
// cout << "73";
t[mp[it]] -= l;
t[c[i]] = a[c[i]];
cnt += l;
break;
}
else {
// cout << 2;
l -= t[mp[it]];
cnt += t[mp[it]];
t[mp[it]] = 0;
s.erase(it);
s.insert(INF + it);
if(list[it]) s.insert(list[it]);
if(s.size()) it = *s.begin();
else {
flag = 0; break;
}
}
}
ans += cnt;
if(flag == 0) break;
}
//cout << ans << t[1] << t[2] << endl;
rep(i, 1, n) ans += t[i];
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while(T--) sol();
return 0;
}
/*
2
3 1
3 3 3
8 1
2 2
5 2
1 2
2 1
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
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
Time Limit Exceeded
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