結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー りあんりあん
提出日時 2018-02-06 22:35:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,847 bytes
コンパイル時間 3,025 ms
コンパイル使用メモリ 215,076 KB
実行使用メモリ 32,132 KB
最終ジャッジ日時 2023-09-26 14:18:16
合計ジャッジ時間 11,463 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 216 ms
15,440 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 35 ms
5,524 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll inf = numeric_limits<ll>::max()/3;

int n;
ll k;
vector< P > tasks;

ll tree[1000000];

void init(int k,int l,int r){
  if(r - l == 1){
    tree[k] = -inf; // init leaf
  }else{
    int chl = k*2+1;
    int chr = k*2+2;
    tree[k] = -inf; // init internal-node
    init(chl, l, (l+r)/2);
    init(chr, (l+r)/2, r);
  }
}

void update(int i,int x,int k,int l, int r){
  if(l <= i && i < r){
    if(r - l == 1){
      tree[k] = x;
    }else{
      int chl = k*2+1;
      int chr = k*2+2;
      update(i,x,chl,l,(l+r)/2);
      update(i,x,chr,(l+r)/2,r);
      tree[k] = max(tree[chl],tree[chr]);
    }
  }
}

ll find(int a,int b,int k,int l,int r){
  // not cross
  if(r <= a || b <= l)return -inf;
  // [a,b) contain [l,r)
  else if(a <= l && r <= b)return tree[k];
  // otherwise
  else{
    int chl = k*2+1;
    int chr = k*2+2;
    ll vl = find(a,b,chl,l,(l+r)/2);
    ll vr = find(a,b,chr,(l+r)/2,r);
    return max(vl,vr);
  }
}


bool detect(ll m){
  ll last = -inf;
  for(int i = 0;i < n;++i){
    if(tasks[i].second > m){
      if(tasks[i].first - last < k)
        return false;
      last = tasks[i].first;
    }
  }
  return true;
}


int main(void){
  cin >> n >> k;
  tasks.clear();

  // find dmax (by bsearch)
  ll tot = 0;
  set< ll > diff_set;
  vector< ll > diff_vec;
  diff_set.insert(0LL);
  for(int i = 0;i < n;++i){
    ll t,d;
    cin >> t >> d;
    tasks.push_back(P(t,d));
    diff_set.insert(d);
    tot += d;
  }
  for(auto d : diff_set){
    diff_vec.push_back(d);
  }
  sort(diff_vec.begin(),diff_vec.end());
  int l = -1,r = (int)diff_vec.size()-1;
  while(r - l > 1){
    int mid = (l+r)/2;
    //cout << diff_vec[mid] << " " << detect(diff_vec[mid]) << endl;
    if(detect(diff_vec[mid]))
      r = mid;
    else
      l = mid;
  }
  ll dmax = diff_vec[r];

  // remove unavalilable tasks
  vector< ll > used;
  used.push_back(-inf);
  for(int i = 0;i < n;++i){
    if(tasks[i].second > dmax){
      used.push_back(tasks[i].first);
      tot -= tasks[i].second;
    }
  }
  used.push_back(inf);
  vector< P > tasks2;
  int j = 1;
  for(int i = 0;i < n;++i){
    while(used[j] < tasks[i].first) ++j;
    if(used[j-1] + k <= tasks[i].first &&
       tasks[i].first <= used[j] - k){
      tasks2.push_back(tasks[i]);
    }
  }

  // find optimal sum
  int size = (int)tasks2.size();
  init(0,0,size+1);
  vector< ll > tms;
  tms.push_back(0);
  update(0,0,0,0,size+1);
  for(int i = 0;i < size;++i){
    int j = (upper_bound(tms.begin(), tms.end(), tasks2[i].first - 1)
             - tms.begin());
    ll calc = find(0,j+1,0,0,size+1);
    update(i+1,calc+tasks2[i].second,0,0,size+1);
    tms.push_back(tasks2[i].first + k);
  }
  cout << dmax << endl;
  cout << tot - find(0,size+1,0,0,size+1) << endl;
  return 0;
}
0