#include <iostream> #include <algorithm> #include <string> using namespace std; int main() { int n; while (cin >> n && n != 0) { int *a = new int[n]; for (int i = 0; i < n; ++i) { cin >> a[i]; } int x,y; for (int i = 0; i < n; ++i) { cin >> x; y=0; for (int j = 0; j <= i; ++j) { if (a[j]-x>=0){ y=y+x; a[j]=a[j]-x; }else{ y=y+a[j]; a[j]=0; } } if (i==n-1){ cout<<y<<endl; }else{ cout<<y<<" "; } } } return 0; } |
Double click to view unformatted code.