Skip to content

Instantly share code, notes, and snippets.

@alculquicondor
Created November 1, 2012 16:55
Show Gist options
  • Save alculquicondor/3995010 to your computer and use it in GitHub Desktop.
Save alculquicondor/3995010 to your computer and use it in GitHub Desktop.
#include <iostream>
#define MAXN 1001
using namespace std;
int main() {
int n, k, d[MAXN], s[MAXN], m[MAXN];
cin>>n>>k;
for(int i=0; i<n; i++)
cin>>d[i];
for(int i=0; i<n; i++)
cin>>s[i];
m[0] = s[0];
for(int i=1; i<n; i++)
m[i] = max(m[i-1], m[i]);
long long f = 0, ans = 0;
int r;
for(int i=0; i<n; i++) {
f += s[i];
while(f<d[i]) {
ans += k;
f += m[i];
}
ans += d[i];
f -= d[i];
}
cout<<ans<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment