QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#744599 | #9528. New Energy Vehicle | zxcdxw | WA | 0ms | 3616kb | C++14 | 2.2kb | 2024-11-13 22:35:16 | 2024-11-13 22:35:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define ll long long
#define lowbit(x) (x)&(-x)
//#define int long long
//#define double long double
const int N = 2e5 + 5;
const ll base = 131;
const ll mod = 998244353;
void solve() {
int n, m;
cin >> n >> m;
vector<int>a(n + 1), b(n + 1);
ll sum = 0;
for (int i = 1; i <= n; ++i) cin >> a[i], sum += a[i], b[i] = a[i];
vector<pair<int, int>>w(m + 1);
vector<set<int>>h(n + 1);
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>>q;
for (int i = 1; i <= m; ++i) {
cin >> w[i].first >> w[i].second;
h[w[i].second].insert(w[i].first);
}
for (int i = 1; i <= n; ++i) {
if (h[i].empty()) q.push({ 2e9,i });
else q.push({ *h[i].begin(),i });
}
ll now = 0;
//cerr<<now<<'\n';
//cerr<<q.size()<<'\n';0
for (int i = 1; i <= m; ++i) {
ll sum = 0;
while (!q.empty()) {
auto u = q.top().first;
auto v = q.top().second;
if (sum + now + b[v] < w[i].first) {
sum += b[v];
b[v] = 0;
q.pop();
//cerr<<v<<'\n';
continue;
}
else {
b[v] -= (w[i].first - sum - now);
now = w[i].first;
if (v == w[i].second) q.pop();
//cerr<<v<<'\n';
break;
}
}
if (now != w[i].first) {
//cerr<<i<<'\n';
break;
}
else {
b[w[i].second] = a[w[i].second];
h[w[i].second].erase(h[w[i].second].begin());
if (!h[w[i].second].empty()) q.push({ *h[w[i].second].begin(),w[i].second });
//if(q.top().second==w[i].second) q.pop();
}
}
//cerr<<1<<'\n';
//cerr<<now<<'\n';
//cerr<<q.size()<<'\n';
for (int i = 1; i <= n; ++i) {
//cerr << b[i] << " ";
now += b[i];
}
cout << now << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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 5 0 5 0 2000000000
result:
wrong answer 2nd lines differ - expected: '11', found: '5'