View Code of Problem 3829

import java.util.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader brd = new BufferedReader(new InputStreamReader(System.in));
		String string;
		while((string = brd.readLine() )!= null) {
			int n =Integer.parseInt(string);
			int[] a = new int[n];
			int[] e = new int[n];
			String[] A = brd.readLine().split(" ");
			for(int i =0;i<n;i++) {
				a[i]=Integer.parseInt(A[i]);
			}
			String[] B = brd.readLine().split(" ");
			for(int i =0;i<n;i++) {
				int b=Integer.parseInt(B[i]);
				for(int j =0;j<=i;j++) {
					if(a[j]<=0) {
						continue;
					}
					a[j]-=b;
					if(a[j]>=0) {
						e[i]+=b;
					}else {
						e[i]+=(a[j]+b);
						a[j]=0;
					}
				}
			}			
			for(int i =0;i<n-1;i++) {
				System.out.print(e[i]+" ");
			}
			System.out.println(e[n-1]);
		}		
	}
}

Double click to view unformatted code.


Back to problem 3829