Codeforces Round #476 (Div. 2) [Thanks, Telegram!] C

http://codeforces.com/contest/965/problem/C

 

 

The main idea of ​​the title: n candies, k people, can only take M candies at most at a time, starting from the first person, you can cycle D times. How many candies can Arkady take? Arkady is the first

 

Ideas:

Suppose you take x candies each time and cycle i times, so greed is x*(d-1)*k + x <= n

Just find x

 

Exploding LL is really annoying

// See if it will explode int! Will the array be one dimension less!
// The fetch problem must be careful of the conditions for the first mover to win
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker,"/STACK:102400000,102400000")
#define LL long long
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define haha printf("haha\n")
LL n, k, m, d;


int main(){
    cin >> n >> k >> m >> d;
    LL ans = min(n, m);
    for (LL i = 1; i <= d; i++){
        LL tmp = (i-1) * k + 1;
        if (tmp <= 0) continue;
        LL x = n / tmp;
        if (x > m) x = m;
        if (x * (i - 1) > (n - x) / k) continue;
        LL res = x * (i-1) + x;
        if (res > ans){
            years = res;
        }
    }
    cout << ans <<endl;
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325071855&siteId=291194637