結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー AshurnasirpalAshurnasirpal
提出日時 2018-02-06 19:27:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,172 bytes
コンパイル時間 2,951 ms
コンパイル使用メモリ 158,812 KB
実行使用メモリ 28,368 KB
最終ジャッジ日時 2023-09-26 05:28:10
合計ジャッジ時間 11,071 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 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 206 ms
15,852 KB
testcase_18 AC 27 ms
4,932 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 272 ms
19,292 KB
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 AC 31 ms
5,252 KB
testcase_32 AC 37 ms
5,620 KB
testcase_33 WA -
testcase_34 AC 303 ms
19,008 KB
testcase_35 WA -
testcase_36 AC 313 ms
20,572 KB
testcase_37 WA -
testcase_38 AC 297 ms
19,108 KB
権限があれば一括ダウンロードができます

ソースコード

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;

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);
  }
  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(j <= n && 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
  vector< P > dp;
  dp.push_back(P(0,0));
  for(int i = 0;i < (int)tasks2.size();++i){
    int j = (upper_bound(dp.begin(), dp.end(), P(tasks2[i].first, inf))
             - dp.begin()) - 1;
    dp.push_back(P(tasks2[i].first + k, dp[j].second + tasks2[i].second));
    /*
    for(int i = 0;i < (int)dp.size();++i){
      printf("(%lld, %lld) ",dp[i].first,dp[i].second);
    }
    cout << endl;
    */
  }
  ll res = 0;
  for(int i = 0;i < (int)dp.size();++i){
    res = max(res,dp[i].second);
  }
  cout << dmax << endl;
  cout << tot - res << endl;
  
  /*
  for(int i = 0;i < (int)tasks2.size();++i){
    cout << tasks2[i].first << " " << tasks2[i].second << endl;
  }
  */
  return 0;
}
0