Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- #define OO 1e18
- using namespace std;
- const int N = 1e7 + 500;
- ll Memo[N];
- ll n ,x ,y;
- ll minTime( int n ){
- if( Memo[n] != -1 ) return Memo[n];
- if( n < 0 ) return +OO;
- if( n % 2 ){
- ll c1 = x + minTime( n-1 );
- ll c2 = y + minTime( (n-1)/2 ) + x;
- return ( Memo[n] = min(c1,c2) );
- }else{
- ll c1 = x + minTime( n-1 );
- ll c2 = y + minTime( n/2 );
- return ( Memo[n] = min(c1,c2) );
- }
- }
- int main()
- {
- cin >> n >> x >> y;
- memset(Memo , -1 , sizeof(Memo));
- Memo[0] = 0; Memo[1] = x;
- ll Ans = minTime(n);
- cout << Ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement