QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#193858 | #7523. Partially Free Meal | ucup-team1516# | WA | 92ms | 14812kb | C++17 | 2.2kb | 2023-09-30 17:58:32 | 2023-09-30 17:58:37 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
inline double time() {
return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n; cin >> n;
vector<pair<ll,ll>> v(n);
vector<pair<ll,int>> bg;
for (int i = 0; i < n; ++i) {
ll a,b; cin >> a >> b;
v[i] = {b, a};
bg.push_back({a+b, i});
}
sort(v.begin(), v.end());
sort(bg.rbegin(), bg.rend());
priority_queue<ll, vector<ll>, greater<ll>> mi;
priority_queue<ll> pq;
ll sum = 0; int cnt = 0; int r = 0;
ll mxb = 0;
for (int i = 0; i < n; ++i) {
if (i == r) {
pq.push(v[r].second);
cnt += 1;
sum += v[r].second;
mxb = v[r].first;
r += 1;
}
else {
cnt += 1;
sum += mi.top();
pq.push(mi.top());
mi.pop();
}
while (bg.size()) {
ll cur = pq.top() + mxb;
ll u = bg.back().first;
if (u <= cur) {
int idx = bg.back().second;
while (r <= idx) {
if (pq.top() + mxb >= v[r].first + v[r].second) {
sum -= pq.top(); sum += v[r].second;
mi.push(pq.top()); pq.pop();
pq.push(v[r].second);
mxb = v[r].first;
}
else {
mi.push(v[r].second);
}
r += 1;
}
bg.pop_back();
}
else break;
}
while (mi.size() and mi.top() < pq.top()) {
sum -= pq.top(); sum += mi.top();
mi.push(pq.top()); pq.pop();
pq.push(mi.top()); mi.pop();
}
ll res = sum + mxb;
cout << res << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 92ms
memory: 14812kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
177355 181575 190262 202788 220014 239595 262995 290249 337332 388219 461663 549763 642923 738718 840595 951758 1073830 1202554 1352495 1508113 1670458 1834409 2013030 2207025 2407326 2608196 2818004 3035259 3277330 3527877 3779431 4033073 4288473 4543952 4804193 5064789 5326437 5588914 5855094 6121...
result:
wrong answer 1st lines differ - expected: '1318594', found: '177355'