QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#194956 | #7523. Partially Free Meal | ucup-team484# | WA | 1007ms | 20156kb | C++17 | 2.0kb | 2023-09-30 23:54:21 | 2023-09-30 23:54:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T> void print(T & x){ cout << x; }
template<class T,class U> void print(pair<T,U> & p){cout << "("; print(p.first); cout << ", "; print(p.second); cout << ")"; }
template<class T> void print(vector<T> & v) {
cout << "{";
if (sz(v)) print(v[0]);
for (int i = 1; i < sz(v); i++) cout << ", ", print(v[i]);
cout << "}\n";
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int N;
cin >> N;
vector<pii> A(N);
for(int i=0; i<N; i++){
cin >> A[i].second >> A[i].first;
}
sort(A.begin(), A.end());
vector<tuple<int,int,int,int>> curI, nxtI;
nxtI.emplace_back(1, N, 0, N-1);
vector<ll> res(N+1);
while(sz(nxtI)){
curI = nxtI;
nxtI.clear();
multiset<ll> S;
ll sum = 0;
S.insert(A[0].second);
sum += A[0].second;
int itcnt = 1;
auto kit = S.begin();
for(auto [l,r,lb,rb] : curI){
int k = (l+r)/2;
for(int b=lb+1; b<k; b++){
ll curpiv = *kit;
S.insert(A[b].second);
if(A[b].second < curpiv){
sum += A[b].second - curpiv;
kit--;
}
}
while(itcnt < k){
//cout << sz(S) << " " << itcnt << " " << k << endl;
kit++;
sum += *kit;
itcnt++;
}
int bestb = max(lb, k-1);
ll bestv = A[bestb].first + sum;
//cout << "start " << k << " with " << bestb << " , " << bestv << endl;
for(int b=bestb+1; b<=rb; b++){
ll curpiv = *kit;
S.insert(A[b].second);
if(A[b].second < curpiv){
sum += A[b].second - curpiv;
kit--;
}
ll curv = A[b].first + sum;
if(curv < bestv){
bestv = curv;
bestb = b;
}
}
res[k] = bestv;
if(l < k){
nxtI.emplace_back(l, k-1, lb, bestb);
}
if(k < r){
nxtI.emplace_back(k+1, r, bestb, rb);
}
}
}
for(int i=1; i<=N; i++){
cout << res[i] << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3388kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1007ms
memory: 20156kb
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 350269351 5570526 7340845 -150611591756 11149865 12332210 -149714935084 14788280 16172895 -168093588281 19336633 20693779 -167477198896 23389851 25073157 -166859133904 28509336 30294967 -166232824672 33976461 35893858 -185399139820 39588384 41470886 -185103737998 45309771 47309654 -194400643...
result:
wrong answer 2nd lines differ - expected: '3208018', found: '350269351'