QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#195116#7523. Partially Free Mealucup-team484#TL 1ms3468kbC++172.3kb2023-10-01 00:59:592023-10-01 00:59:59

Judging History

你现在查看的是最新测评结果

  • [2023-10-01 00:59:59]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3468kb
  • [2023-10-01 00:59:59]
  • 提交

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){
      //cout << l << " " << r << " " << lb << " " << rb << " " << sz(S) << " " << itcnt << endl;
      int k = (l+r)/2;
      for(int b=itcnt+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--;
        }
      }
      //cout << l << " " << r << " " << lb << " " << rb << " " << sz(S) << " " << itcnt << endl;
      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: 3468kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Time Limit Exceeded

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:


result: