Submission #1010791

# Submission time Handle Problem Language Result Execution time Memory
1010791 2024-06-29T11:19:07 Z vivkostov Remittance (JOI19_remittance) C++14
0 / 100
1 ms 2648 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
long long int n,a[200005],b[200005],bra,brb;
void rec(int num,long long int mah,int br)
{
    if(num==0)num=n;
    if(num>n)num=1;
    if(br==n)
    {
        cout<<"Yes"<<endl;
        return;
    }
    if(bra-mah<brb)
    {
        cout<<"No"<<endl;
        return;
    }
    a[num]-=mah;
    /*cout<<num<<" "<<mah<<" "<<br<<endl;
    for(long long int i=1;i<=n;i++)
    {
        cout<<a[i]<<" ";
    }
    cout<<endl;
    */
    if(a[num]==b[num])
    {
        rec(num+1,0,br+1);
    }
    else if(a[num]-b[num]>0)
    {
        if((a[num]-b[num])%2==0)
        {
            long long int h=(a[num]-b[num]);
            a[num]=b[num];
            rec(num+1,-h/2,0);
        }
        else
        {
            long long int h=(a[num]-b[num]);
            a[num]=b[num]-1;
            rec(num+1,-h/2-1,0);
        }
    }
    else
    {
        rec(num-1,(b[num]-a[num])*2,0);
    }
}
void read()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i];
        bra+=a[i];
        brb+=b[i];
    }
    rec(1,0,0);
}
int main()
{
    speed();
    read();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2436 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2392 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2436 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2392 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 0 ms 2436 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Incorrect 1 ms 2392 KB Output isn't correct
6 Halted 0 ms 0 KB -