-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10170.cpp
36 lines (32 loc) · 822 Bytes
/
P10170.cpp
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
#include <iostream>
#include <stdio.h>
typedef unsigned long long ul;
ul daysUsedBy(ul group, ul S) {
return ((2*S+group)*(group+1))/2;
}
// S = initial group size staying for S days.
// D = Day where group size is measured.
ul groupAtDay(ul S, ul D) {
if(D <= S)
return S;
ul s = S; // Smaller than the group at the hotel at day D.
ul h = S+D; // Larger than or equal to group at day D.
while(s < h-1) {
ul mid = (s+h)/2;
//std::cerr << "Search day " << D << ", low=" << s << ", high=" << h << ", mid=" << mid << ", days for mid=" << daysUsedBy(mid-S, S) << std::endl;
if(daysUsedBy(mid-S, S) < D) {
s = mid;
}
else {
h = mid;
}
}
return h;
}
int main() {
ul S, D;
while(std::cin >> S >> D) {
std::cout << groupAtDay(S, D) << std::endl;
}
return 0;
}