I am a beginner level coder. I’m stuck at this problem Courses - Codeforces
and here is my code
my_code - Pastebin.com
Please let me know where I am doing wrong
The upper bound for the answer can be as large as 2 \times10^9. Because
N\le 2\times10^8 \ \text{and }\ x \le10 \implies N\times x \le 2 \times 10^9
This should pass ig haven't tested though
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mp make_pair
#define ff first
#define Ss second
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
ll n;
ll x, y;
bool good(ll p)
{
ll m = ((p - min(x, y)) / max(x, y)) + (p / min(x, y));
return m >= n;
}
int main()
{
cin >> n >> x >> y;
ll l = 0;
ll r = 2e9 ;
while (l + 1 < r)
{
ll mid = (l + r) / 2;
if (good(mid))
{
r = mid;
}
else
l = mid;
}
cout << r << endl;
return 0;
}
Yeah ! it did solve my problem. Thanks
I’ve learnt certain things, thanks