QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682336 | #9528. New Energy Vehicle | ucup-team2432# | RE | 0ms | 3532kb | C++20 | 1.6kb | 2024-10-27 15:02:44 | 2024-10-27 15:02:45 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(vec) ((ll)vec.size())
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using db = double;
using i128 = __int128;
#define Emu Smile
using namespace std;
const ll inf = 1e18;
void yes() { cout << "Yes\n"; }
void no() { cout << "No\n"; }
void chmax(auto &a,auto b) { if (a < b) a = b; }
void chmin(auto &a,auto b) { if (a > b) a = b; }
void solve() {
int n,m; cin >> n >> m;
vector<ll> a(n);
for (auto &x : a) {
cin >> x;
}
vector eg(n, vector<ll>());
vector<int> c(n), p(n), be(n);
for (int i = 0, x; i < m; ++i) {
cin >> c[i] >> x; x--;
eg[x].emplace_back(i);
be[i] = x;
}
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<>> q;
vector<ll> remain(n);
for (int i = 0; i < n; ++i) {
eg[i].emplace_back(inf);
remain[i] = a[i];
q.emplace(eg[i][0], i);
}
ll ret = 0;
for (int i = 0; i < m; ++i) {
while (!q.empty()) {
auto [pos, id] = q.top();
ll mint = min(c[i] - ret, remain[id]);
ret += mint, remain[id] -= mint;
if (!remain[id]) { q.pop(); }
if (ret == c[i]) break;
}
if (ret == c[i]) {
int id = be[i];
if (q.top().second == id) { q.pop(); }
remain[id] = a[i]; p[id] ++;
q.emplace(eg[i][p[id]], i);
} else {
break;
}
}
for (auto x : remain) {
ret += x;
}
cout << ret << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
// freopen("test.in","r",stdin);
// freopen("test.out","w",stdout);
cout << fixed << setprecision(10);
// init();
int OuO = 1;
cin >> OuO;
for (int piastic = 0; piastic < OuO; ++piastic) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
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
Runtime Error
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