-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee3351.cpp
More file actions
51 lines (40 loc) · 839 Bytes
/
Copy pathbee3351.cpp
File metadata and controls
51 lines (40 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Contest : Beecrowd
* Problem : 3351 - Clickbait
* Link : https://judge.beecrowd.com/pt/problems/view/3351
* Time : O(N * logK)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
vector<pair<ll, ll>> v; // {primeiro momento, tempo até voltar a assistir dnv}
ll n, k;
bool valid(ll x) {
ll cnt = 0;
for (auto &[begin, t] : v) {
if (begin <= x) cnt += 1 + (x - begin) / t;
if (cnt >= k) return true;
}
return cnt >= k;
}
ll bs() {
ll l = 1, r = 2e18 + 1;
while (l <= r) {
ll m = l + (r-l)/2;
if (valid(m))
r = m - 1;
else
l = m + 1;
}
return l;
}
int main() {
fastio
cin >> n >> k;
v.assign(n, {});
for (auto &[begin, t] : v)
cin >> begin >> t;
cout << bs() << '\n';
return 0;
}