Submission #1220581

#TimeUsernameProblemLanguageResultExecution timeMemory
1220581badge881Remittance (JOI19_remittance)C++20
100 / 100
148 ms16072 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int MXN = 1e6 + 6;

int n;
ll A[MXN], B[MXN];

int32_t main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld%lld", &A[i], &B[i]);
    int i = 0, it = 0;
    while (it < n)
    {
        if (A[i] <= B[i] || (A[i] == 1 && B[i] == 0))
        {
            it++;
            (++i) %= n;
            continue;
        }
        it = 0;
        int j = i;
        while (A[j] > B[j] && !(A[j] == 1 && B[j] == 0))
        {
            ll send = (A[j] - B[j] + (B[j] != 0)) >> 1;
            A[j] -= send << 1;
            A[(++j) %= n] += send;
        }
    }
    for (int i = 0; i < n; i++)
        if (A[i] != B[i])
        {
            printf("No\n");
            return 0;
        }
    printf("Yes\n");
    return 0;
}

Compilation message (stderr)

remittance.cpp: In function 'int32_t main()':
remittance.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
remittance.cpp:15:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         scanf("%lld%lld", &A[i], &B[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...