Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

ajitkumar014's blog

By ajitkumar014, history, 14 months ago, In English

unable to understand why if(last*2 < g) is done,please someone explain. Thankyou.

include "bits/stdc++.h"

using namespace std;

int main() { int t; scanf ("%d", &t); while (t--) { long long n, k, g; scanf ("%lld %lld %lld", &n, &k, &g);

    long long stolen = min((g - 1) / 2 * n, k * g);
    long long rest = (k * g - stolen) % g;

    if (rest > 0) {
        stolen -= (g - 1) / 2;
        long long last = ((g - 1) / 2 + rest) % g;

        if (last * 2 < g) {
            stolen += last;
        } else {
            stolen -= g - last;
        }
    }

    printf ("%lld\n", stolen);
}

}

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
14 months ago, # |
  Vote: I like it 0 Vote: I do not like it

This solution is very elegant and clear. Hope it helps. https://codeforces.net/contest/1836/submission/210131874