Submission #925026

# Submission time Handle Problem Language Result Execution time Memory
925026 2024-02-10T13:26:19 Z boris_mihov Remittance (JOI19_remittance) C++17
0 / 100
3 ms 4700 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <set>

typedef long long llong;
const int MAXN = 1e6 + 10;
const int MAXLOG = 20;
const int INF  = 2e9;

int n;
int a[MAXN];
int b[MAXN];
std::queue <int> q;

void solve()
{
    for (int i = 1 ; i <= n ; ++i)
    {
        if (a[i] - b[i] > 1)
        {
            q.push(i);
        }
    }
    
    while (q.size())
    {
        int idx = q.front();
        q.pop();

        assert(a[idx] - b[idx] > 1);
        int cnt = (a[idx] - b[idx]) / 2;
        a[idx % n + 1] += cnt;
        a[idx] -= 2 * cnt;

        if (a[idx % n + 1] - b[idx % n + 1] > 1)
        {
            q.push(idx % n + 1);
        }
    }

    for (int i = 1 ; i <= n ; ++i)
    {
        if (a[i] < b[i])
        {
            std::cout << "No\n";
            return;
        }
    }

    std::cout << "Yes\n";
}

void input()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i] >> b[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}   

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Runtime error 3 ms 4700 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Runtime error 3 ms 4700 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Runtime error 3 ms 4700 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -