View Code of Problem 3829

import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in =new Scanner(System.in);
		while(in.hasNext()) {
			int n =in.nextInt();
			int[] a = new int[n];
			int[] b = new int[n];
			int[] e  =new int[n];
			for(int i =0;i<n;i++) {
				a[i]=in.nextInt();
			}
			for(int i =0;i<n;i++) {
				b[i]=in.nextInt();
			}			
			for(int i =0;i<n;i++) {
				for(int j =0;j<=i;j++) {
					if(a[j]<=0) {
						continue;
					}
					a[j]-=b[i];
					if(a[j]>=0) {
						e[i]+=b[i];
					}else {
						e[i]+=(a[j]+b[i]);
						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