結果
問題 | No.817 Coin donation |
ユーザー |
|
提出日時 | 2020-08-01 22:32:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 812 bytes |
コンパイル時間 | 1,665 ms |
コンパイル使用メモリ | 72,040 KB |
最終ジャッジ日時 | 2025-01-12 12:54:55 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 14 |
ソースコード
#include <iostream> #include <vector> using lint = long long; void solve() { int n; lint k; std::cin >> n >> k; std::vector<std::pair<lint, lint>> ps(n); for (auto& p : ps) std::cin >> p.first >> p.second; lint ok = 0, ng = 1 << 30; // the number of coins less than ok is smaller than k while (ng - ok > 1) { lint mid = (ok + ng) / 2; lint sum = 0; for (auto p : ps) { if (mid <= p.first) continue; lint r = std::min(mid - 1, p.second); sum += r - p.first + 1; } if (sum < k) { ok = mid; } else { ng = mid; } } std::cout << ok << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }