結果

問題 No.817 Coin donation
ユーザー cotton_fn_
提出日時 2019-04-19 21:49:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 1,166 ms
コンパイル使用メモリ 115,900 KB
最終ジャッジ日時 2025-01-07 02:40:31
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n, k;
vector<pair<i64, i64>> ps;
int main() {
  cin >> n >> k;
  init_n(ps, n);
  for (i64 i = 0; i < n; ++i) {
    cin >> ps[i].first >> ps[i].second;
  }
  sort(begin(ps), end(ps));

  i64 l = 0, r = 1e9 + 1;
  while (r - l > 1) {
    i64 m = l + (r - l) / 2, c = 0;
    for (auto p : ps) {
      i64 a = p.first, b = min(m, p.second);
      c += max(i64(0), b - a + 1);
    }
    cerr << l << '\t' << r << '\t'<< c << '\n';
    if (c < k) l = m;
    else r = m;
  }
  cout << l + 1 << '\n';
  return 0;
}
0