제출 #1010794

#제출 시각아이디문제언어결과실행 시간메모리
1010794vivkostov송금 (JOI19_remittance)C++14
0 / 100
1 ms2396 KiB
#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,cycle; void rec(int num,long long int mah,int br,int cycle) { if(cycle==100000000) { cout<<"No"<<endl; return; } 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,cycle+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,cycle+1); } else { if(a[num]==1) { rec(num-1,1,0,cycle+1); return; } long long int h=(a[num]-b[num]); a[num]=b[num]-1; rec(num+1,-h/2-1,0,cycle+1); } } else { rec(num-1,(b[num]-a[num])*2,0,cycle+1); } } 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,0); } int main() { speed(); read(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...