-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcandies.cpp
More file actions
50 lines (46 loc) · 868 Bytes
/
candies.cpp
File metadata and controls
50 lines (46 loc) · 868 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pop pop_back
int main()
{
ll n;
cin>>n;
ll cm=0;
if(n<=42){
cout<<1;
}else{
if(n%2==0){
cm=n/2;
}else{
cm=(n+1)/2;
}
ll lo=1;
ll hi=n;
//ll ans=0,wr=0;
while((hi-lo)>1){
ll mid=(hi+lo)/2;
ll k=n-mid,pet=0,vas=mid;
while(k>0){
ll g=k/10;
pet+=g;
k-=g;
if(k<mid){
vas+=k;
k=0;
}else{
k-=mid;
vas+=mid;
}
}
if(vas>=cm){
hi=mid;
}else if(pet>=cm){
lo=mid;
}
}
cout<<hi;
}
return 0;
}