結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー ei1333333ei1333333
提出日時 2016-11-18 23:06:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,569 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 171,300 KB
実行使用メモリ 9,428 KB
最終ジャッジ日時 2024-05-04 18:20:04
合計ジャッジ時間 6,194 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,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 137 ms
7,508 KB
testcase_18 AC 23 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 64 ms
5,376 KB
testcase_21 AC 180 ms
8,272 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 27 ms
5,376 KB
testcase_32 AC 30 ms
5,376 KB
testcase_33 WA -
testcase_34 AC 193 ms
8,400 KB
testcase_35 WA -
testcase_36 AC 194 ms
8,660 KB
testcase_37 WA -
testcase_38 AC 193 ms
8,044 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

typedef long long int64;

vector< int64 > vv;
int64 N, K, T[200000], D[200000];

int main()
{


  cin >> N >> K;
  priority_queue< pair< int, int >, vector< pair< int, int > >, greater< pair< int, int > > > que;

  for(int i = 0; i < N; i++) {
    cin >> T[i] >> D[i];
    que.emplace(T[i], i);
  }

  int low = 0, high = 1 << 30;
  while(high - low > 0) {
    int mid = (low + high) >> 1;

    int64 prev = -1145141919810LL;
    bool flag = true;
    for(int i = 0; i < N; i++) {
      if(mid < D[i]) {
        if(T[i] - prev < K) flag = false;
        prev = T[i];
      }
    }

    if(flag) high = mid;
    else low = mid + 1;
  }

  int64 all = 0;

  vv.push_back(-1145141919810LL);
  for(int i = 0; i < N; i++) {
    if(D[i] > low) {
      vv.push_back(T[i]);
      all += D[i];
    }
  }
  vv.push_back(1145141919810LL);

  for(int i = 1; i < vv.size(); i++) {
    vector< int > arrays;
    while(!que.empty() && que.top().first < vv[i - 1] + K) {
      que.pop();
    }
    while(!que.empty() && que.top().first <= vv[i] - K) {
      arrays.push_back(que.top().second);
      que.pop();
    }
    vector< int64 > dp(arrays.size() + 1, 0);
    for(int j = 0; j < arrays.size(); j++) {
      if(j > 0) dp[j] = max(dp[j], dp[j - 1]);
      int curr = lower_bound(arrays.begin(), arrays.end(), T[arrays[j]] + K) - arrays.begin();
      dp[curr] = max(dp[curr], dp[j] + D[arrays[j]]);
    }
    all += *max_element(begin(dp), end(dp));
  }
  cout << low << endl;
  cout << accumulate(D, D + N, 0LL) - all << endl;

}


0