Submission #1129981

#TimeUsernameProblemLanguageResultExecution timeMemory
1129981Username_taken12Remittance (JOI19_remittance)Java
100 / 100
514 ms158140 KiB
import java.io.*; import java.util.StringTokenizer; public class remittance { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int N = Integer.parseInt(r.readLine()); int[] val = new int[N]; int sb=0; int sa=0; for(int i=0; i<N; i++){ StringTokenizer st = new StringTokenizer(r.readLine()); int a =Integer.parseInt(st.nextToken()); int b =Integer.parseInt(st.nextToken()); sb+=b; sa+=a; val[i]=a-b; } if(sb==0) { if(sa==0) pw.println("Yes"); else pw.println("No"); pw.close(); return; } //int las=N-1; int cnt=0; for(int i=0; i<N; i=(i+1)%N){ if(val[i]<=0){ cnt++; if(cnt==2*N) break; continue; } int t = (val[i]+1)/2; val[i]-=2*t; val[(i+1)%N]+=t; cnt=0; } boolean w = true; for(int i=0; i<N; i++) if(val[i]!=0) w=false; if(w) pw.println("Yes"); else pw.println("No"); pw.close(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...