QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#683060 | #9528. New Energy Vehicle | fgz# | TL | 0ms | 3844kb | C++23 | 1.9kb | 2024-10-27 18:35:49 | 2024-10-27 18:35:49 |
Judging History
answer
#include<bits/stdc++.h>
#define ios ios::sync_with_stdio(0), cin.tie(0)
#define time chrono::system_clock::now().time_since_epoch().count()
using namespace std;
#define int long long
using ll = long long;
using pll = pair<int, int>;
const int mod = 1e9 + 7, N = 2e5 + 10;
void solve(){
int n, m; cin >> n >> m;
vector<int> a(n + 10), st(n + 10);
for (int i = 1; i <= n; i ++) cin >> a[i], st[i] = a[i];
vector<pll> b(m + n + 10);
vector<int> nx(n + m + 10);
for (int i = 1; i <= m; i ++) {
cin >> b[i].first >> b[i].second;
}
for (int i = 1; i <= n; i ++) {
b[m + i] = {1e18, i};
}
vector<int> mp(n + 10, n + m + 1);
for (int i = n + m; i >= 1; i --) {
nx[i] = mp[b[i].second];
mp[b[i].second] = i;
}
multiset<tuple<int, int, int>> s;
for (int i = 1, j = 1; i <= n + 1; i ++) {
int dis = b[i].first - b[i - 1].first;
while (j < i) j ++;
while (s.size() && dis) {
auto [p, id, v] = *s.begin();
s.erase(s.find({p, id, v}));
if (p < i) {
if (nx[p] < j) s.insert({p, id, a[id]});
else continue;
}
int t = min(dis, v);
dis -= t;
a[id] -= t;
if (v - t > 0) s.insert({p, id, v - t});
}
while(dis && j <= n + m) {
int t = min(a[b[j].second], dis);
dis -= t;
a[b[j].second] -= t;
j ++;
}
j--;
if (dis) {
int t = b[i].first - dis;
cout << t << '\n';
return;
}
a[b[i].second] = st[b[i].second];
if (nx[i] >= j) continue;
else {
s.insert({nx[i], b[i].second, a[b[i].second]});
}
}
}
signed main()
{
ios;
int t = 1;
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: 3844kb
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