Submission

Status:
[-SSSSSSSSS][-SSSS]

Score: 0

User: jxkrpn

Problemset: ขนมของเซ้น143 (v.ยาก)

Language: c

Time: 0.101 second

Submitted On: 2024-10-02 12:52:29

#include <stdio.h>
#include <math.h>

// Function to calculate the minimum difference
long long minPartitionDifference(long long N) {
    long long total_sum = N * (N + 1) / 2; // Total sum of numbers from 1 to N
    long long target = total_sum / 2;      // Target sum for one of the groups
    long long groupA_sum = 0;

    // Allocate numbers greedily from largest to smallest to Group A
    for (long long i = N; i > 0; --i) {
        if (groupA_sum + i <= target) {
            groupA_sum += i;
        }
    }

    long long groupB_sum = total_sum - groupA_sum;

    // Return the absolute difference between the two groups
    return llabs(groupA_sum - groupB_sum);
}

int main() {
    long long N;
    scanf("%lld", &N);

    // Output the minimum possible absolute difference
    printf("%lld\n", minPartitionDifference(N));

    return 0;
}