Source Code
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
#define deb(x) cout << #x << " = " << x <<endl
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(c) c.begin(), c.end()
#define endl "\n"
#define sz(u) (int)(u.size())
#define L(x)(2*x)
#define R(x)(2*x+1)
#define M(x,y)((x+y)/2)
#define int long long
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
       cout.tie(0);
    int n,x,y;
    cin>>n>>x>>y;
    int l=0,r=1e18+1,ans=1e18+1;
    if(x>y)
        swap(x,y);
    while(l<=r){
        int md=(l+r)/2;
        int num=md*x;
        int other=num/y;
        if(other+md<n){
            l=md+1;
        }
        else{
            ans=min(ans,max(x*md,(n-md)*y));
            r=md-1;
        }
    }
    cout<<ans;
}
Copy
Hurry up Boredom
GNU G++17
0 ms
744 KB
Wrong Answer