http://codeforces.com/contest/965/problem/C
题目大意:n个糖,k个人,每次最多只能拿M个糖,从第一个人开始拿,可以循环D次。问Arkady最多可以拿几块糖?Arkady 是第一个人
思路:
设每次拿x个糖,循环i次,所以贪心就是x*(d-1)*k + x <= n
求出x就好了
爆LL是真的烦
//看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #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 ") 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){ ans = res; } } cout << ans <<endl; return 0; }