QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#195057 | #7523. Partially Free Meal | ucup-team484# | WA | 983ms | 20164kb | C++17 | 2.1kb | 2023-10-01 00:32:46 | 2023-10-01 00:32:46 |
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;
int itcnt = 0;
auto kit = S.begin();
for(auto [l,r,lb,rb] : curI){
int k = (l+r)/2;
for(int b=lb+1; b<k; b++){
S.insert(A[b-1].second);
if(itcnt != 0 && A[b-1].second < *kit){
ll curpiv = *kit;
sum += A[b-1].second - curpiv;
kit--;
}
}
while(itcnt < k-1){
//cout << sz(S) << " " << itcnt << " " << k << endl;
itcnt++;
if(itcnt == 1){
kit = S.begin();
}
else
kit++;
sum += *kit;
}
int bestb = max(lb, k-1);
ll bestv = A[bestb].first + A[bestb].second + sum;
//cout << "start " << k << " with " << bestb << " , " << bestv << endl;
for(int b=bestb+1; b<=rb; b++){
S.insert(A[b-1].second);
if(itcnt != 0 && A[b-1].second < *kit){
ll curpiv = *kit;
sum += A[b-1].second - curpiv;
kit--;
}
ll curv = A[b].first + A[b].second + 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: 1ms
memory: 3464kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 983ms
memory: 20164kb
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 1318594 5570526 7340845 -150906340403 11149865 12332210 -150014133683 14788280 16172895 -168297230101 19336633 20693779 -167683020277 23389851 25073157 -167066849800 28509336 30294967 -166442807561 33976461 35893858 -185497753766 39588384 41470886 -185203639318 45309771 47309654 -19445242608...
result:
wrong answer 2nd lines differ - expected: '3208018', found: '1318594'