Monday, March 17, 2014

Codeforces Round #236 (Div. 2), problem: (A) Nuts solution

Codeforces Round #236 (Div. 2), problem: (A) Nuts: http://codeforces.com/contest/402/problem/A

Codeforces Round #236 (Div. 2), problem: (A) Nuts solution: http://ideone.com/B6qs7I

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    int k, a, b, v, r;
    r=0;
    scanf("%d%d%d%d", &k, &a, &b, &v);
    while(b+1>=k && a>0) {
        a-=k*v;
        b-=k, b++;
        r++;
    }
    while(b+1<k && a>0) a-=(b+1)*v, b=0, r++;
    while(a>0) a-=v, r++;
    printf("%d\n", r);
    return 0;
}

No comments:

Post a Comment