#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for(int i =(a); i < (b); ++i)
#define re(i, n) FOR(i, 1, n)
#define ford(i, a, b) for(int i = (a); i >= (b); --i)
#define rep(i, n) for(int i = 0;i <(n); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
using namespace std;
typedef long long ll;
typedef pair<ll, int> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll inf = 1e18;
const int maxn = 5005;
vi dp;
struct min_queue
{
deque<ll> mono;
queue<ll> q;
bool is_empty() {return q.empty();}
ll get_min() {return mono.front();}
void push(ll v)
{
q.push(v);
while (!mono.empty() && mono.back() >= v) mono.pop_back();
mono.push_back(v);
}
void pop()
{
int v = q.front();
q.pop();
if (mono.front() == v) mono.pop_front();
}
};
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
ll x, y;
cin >> n >> x >> y;
dp.resize(n+1);
dp[0] = 0;
min_queue q;
for (ll i = 1; i <= n; i++)
{
dp[i] = dp[i-1] + x;
while (q.q.size() > i/2) q.pop();
if (!q.is_empty())
{
ll dupa = q.get_min();
dp[i] = min(dp[i], dupa + y - i*x);
}
q.push(2*i*x + dp[i]);
}
cout << dp[n] << '\n';
}
1204A - BowWow and the Timetable | 508B - Anton and currency you all know |
1672A - Log Chopping | 300A - Array |
48D - Permutations | 677C - Vanya and Label |
1583B - Omkar and Heavenly Tree | 1703C - Cypher |
1511C - Yet Another Card Deck | 1698A - XOR Mixup |
1702E - Split Into Two Sets | 1703B - ICPC Balloons |
1702F - Equate Multisets | 1700A - Optimal Path |
665C - Simple Strings | 1708A - Difference Operations |
1703E - Mirror Grid | 1042A - Benches |
1676B - Equal Candies | 1705B - Mark the Dust Sweeper |
1711A - Perfect Permutation | 1701B - Permutation |
1692A - Marathon | 1066A - Vova and Train |
169B - Replacing Digits | 171D - Broken checker |
380C - Sereja and Brackets | 1281B - Azamon Web Services |
1702A - Round Down the Price | 1681C - Double Sort |