結果

問題 No.817 Coin donation
ユーザー yuppe19 😺yuppe19 😺
提出日時 2019-07-17 12:07:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 73 ms / 2,000 ms
コード長 1,035 bytes
コンパイル時間 728 ms
コンパイル使用メモリ 77,716 KB
実行使用メモリ 7,268 KB
最終ジャッジ日時 2023-08-22 21:51:40
合計ジャッジ時間 2,690 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 10 ms
4,380 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 49 ms
5,704 KB
testcase_09 AC 14 ms
4,376 KB
testcase_10 AC 73 ms
6,964 KB
testcase_11 AC 73 ms
7,268 KB
testcase_12 AC 73 ms
7,020 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(void) {
  int N; size_t K; scanf("%d%lu", &N, &K);
  vector<int> a(N), b(N);
  vector<int> v(N*2);
  for(int i=0, j=0; i<N; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    v[j++] = a[i];
    v[j++] = b[i] + 1;
  }
  vector<int> w = v;
  sort(w.begin(), w.end()); w.erase(unique(w.begin(), w.end()), w.end());
  vector<size_t> per(N*2 + 1);
  for(int i=0, j=0; i<N; ++i) {
    size_t l = lower_bound(w.begin(), w.end(), v[j++]) - w.begin(),
           r = lower_bound(w.begin(), w.end(), v[j++]) - w.begin();
    ++per[l];
    --per[r];
  }
  for(int i=0; i<N*2; ++i) {
    per[i+1] += per[i];
  }
  size_t cnt = 0;
  for(size_t i=0, n=w.size(); i<n-1; ++i) {
    int range = w[i+1] - w[i];
    size_t ncnt = cnt + range * per[i];
    if(ncnt < K) {
      cnt = ncnt;
      continue;
    }
    size_t dif = K - cnt;
    size_t pos = (dif + per[i] - 1) / per[i];
    size_t res = pos + w[i] - 1;
    printf("%lu\n", res);
    return 0;
  }
  throw;
}
0