QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225502 | #7523. Partially Free Meal | PetroTarnavskyi# | WA | 234ms | 25800kb | C++17 | 2.7kb | 2023-10-24 18:44:52 | 2023-10-24 18:44:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const LL LINF = 1e18;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int n;
cin >> n;
VI a(n), b(n), idxes(n);
FOR(i, 0, n)
cin >> a[i] >> b[i];
iota(ALL(idxes), 0);
sort(ALL(idxes), [&](int i, int j) {return b[i] < b[j];});
vector<int> vec;
int mn = INT_MAX;
RFOR(i, n, 0)
{
if (a[idxes[i]] + b[idxes[i]] < mn)
{
mn = a[idxes[i]] + b[idxes[i]];
vec.PB(i);
}
}
reverse(ALL(vec));
vector<LL> ans(n);
int k = 0;
multiset<int> sBig1, sSmall1, sBig2, sSmall2;
LL sum1 = a[idxes[vec[0]]] + b[idxes[vec[0]]], sum2 = 0;
FOR(j, 0, vec[0])
sBig1.insert(a[idxes[j]]);
if (SZ(vec) > 1)
{
FOR(j, 0, vec[1])
sBig2.insert(a[idxes[j]]);
sum2 = a[idxes[vec[1]]] + b[idxes[vec[1]]];
}
ans[0] = sum1;
FOR(i, 0, SZ(vec) - 1)
{
while (k + 1 < n)
{
assert(SZ(sSmall1) == k && SZ(sSmall2) == k);
assert(!sBig2.empty());
LL nsum1 = sum1 + (sBig1.empty() ? LINF : *sBig1.begin());
LL nsum2 = sum2 + *sBig2.begin();
if (nsum2 < nsum1)
break;
assert(!sBig1.empty());
sum1 += *sBig1.begin();
sSmall1.insert(*sBig1.begin());
sBig1.erase(sBig1.begin());
sum2 += *sBig2.begin();
sSmall2.insert(*sBig2.begin());
sBig2.erase(sBig2.begin());
k++;
ans[k] = sum1;
}
sum1 += a[idxes[vec[i + 1]]] + b[idxes[vec[i + 1]]] - (a[idxes[vec[i]]] + b[idxes[vec[i]]]);
FOR(j, vec[i], vec[i + 1])
{
sum1 += a[idxes[j]];
sSmall1.insert(a[idxes[j]]);
}
while (SZ(sSmall1) > k)
{
sum1 -= *prev(sSmall1.end());
sBig1.insert(*prev(sSmall1.end()));
sSmall1.erase(prev(sSmall1.end()));
}
if (i + 2 == SZ(vec))
break;
sum2 += a[idxes[vec[i + 2]]] + b[idxes[vec[i + 2]]] - (a[idxes[vec[i + 1]]] + b[idxes[vec[i + 1]]]);
FOR(j, vec[i + 1], vec[i + 2])
{
sum2 += a[idxes[j]];
sSmall2.insert(a[idxes[j]]);
}
while (SZ(sSmall2) > k)
{
sum2 -= *prev(sSmall2.end());
sBig2.insert(*prev(sSmall2.end()));
sSmall2.erase(prev(sSmall2.end()));
}
}
while (k + 1 < n)
{
assert(SZ(sSmall1) == k);
sum1 += *sBig1.begin();
sSmall1.insert(*sBig1.begin());
sBig1.erase(sBig1.begin());
k++;
ans[k] = sum1;
}
FOR(i, 0, n)
cout << ans[i] << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3884kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 234ms
memory: 25800kb
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:
1318594 3208018 5570526 7340845 9223347 11487338 12898863 14697855 14788280 16172895 17768627 19336633 20693779 22005236 23389851 25073157 26760338 28509336 30294967 32093959 33976461 35893858 37754030 39588384 41470886 43388283 45309771 47573762 49838235 52476909 55158583 58072674 61026526 64003437...
result:
wrong answer 6th lines differ - expected: '11149865', found: '11487338'