can anyone explain the editorial of B. Astrophysicists of codeforces round 880 div-2

Правка en1, от ajitkumar014, 2023-06-29 07:42:23

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);
}

}

Теги doubts

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский ajitkumar014 2023-06-29 07:42:23 699 Initial revision (published)