Submission #147190

# Submission time Handle Problem Language Result Execution time Memory
147190 2019-08-28T11:00:23 Z Alexa2001 Remittance (JOI19_remittance) C++17
0 / 100
3 ms 380 KB
#include <bits/stdc++.h>
#define yes { cout << "Yes\n"; exit(0); }
#define no { cout << "No\n"; exit(0); }

using namespace std;

const int Nmax = 1e6 + 5;
typedef long long ll;

int n;
ll a[Nmax], b[Nmax];

int main()
{
  //  freopen("rem.in", "r", stdin);
    cin.tie(0); cin.sync_with_stdio(false);

    int i, j;
    ll s1 = 0, s2 = 0;

    cin >> n;
    for(i=1; i<=n; ++i) cin >> a[i] >> b[i], s1 += a[i], s2 += b[i];

    while(s1 > s2)
    {
        int i; s1 = 0;
        bool modif = 0;

        for(i=1; i<=n; ++i)
        {
            if(a[i] <= b[i]) continue;

            int nxt = (i<n ? i+1 : 1);

            ll add = (a[i] - b[i]) / 2;

            a[i] -= 2 * add;
            a[nxt] += add;

            modif |= (add > 0);
        }

        if(!modif) break;
        for(i=1; i<=n; ++i) s1 += a[i];
   //cerr << a[i] << ' ';
     //   cerr << '\n';
    }

    for(i=1; i<=n; ++i)
        if(a[i] != b[i]) no

    yes

    return 0;
}

Compilation message

remittance.cpp: In function 'int main()':
remittance.cpp:18:12: warning: unused variable 'j' [-Wunused-variable]
     int i, j;
            ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -