Please read the new rule regarding the restriction on the use of AI tools. ×

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

Revision en1, by 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);
}

}

Tags doubts

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ajitkumar014 2023-06-29 07:42:23 699 Initial revision (published)