-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1249E.cpp
More file actions
33 lines (32 loc) · 722 Bytes
/
1249E.cpp
File metadata and controls
33 lines (32 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n,c;
cin >> n >> c;
ll a[n-1];
ll b[n-1];
for (ll i = 0; i < n-1; i++) {
cin >> a[i];
}
for (ll i = 0; i < n-1; i++) {
cin >> b[i];
}
ll dp[n+1][2];
memset(dp, 10000 , sizeof dp);
dp[0][0]=0;
dp[0][1]=c;
for (ll i = 0; i < n-1; i++) {
dp[i+1][0] = min(dp[i+1][0], dp[i][0] + a[i]);
dp[i+1][0] = min(dp[i+1][0], dp[i][1] + a[i]);
dp[i+1][1] = min(dp[i+1][1], dp[i][1] + b[i]);
dp[i+1][1] = min(dp[i+1][1], dp[i][0] + b[i] + c);
}
for (ll i = 0; i < n; i++) {
cout << min(dp[i][0], dp[i][1]) << " ";
}
}