-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc174-1.cpp
More file actions
44 lines (44 loc) · 947 Bytes
/
arc174-1.cpp
File metadata and controls
44 lines (44 loc) · 947 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
34
35
36
37
38
39
40
41
42
43
44
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr);
#define int long long
const int maxn = 3e5 + 1;
int a[maxn], dp[maxn], sum;
signed main()
{
IOS;
int n, c;
cin >> n >> c;
for (int i = 1; i <= n; i++)
cin >> a[i], sum += a[i];
if (c > 0)
{
for (int i = 1; i <= n; i++)
{
dp[i] = max(dp[i - 1] + a[i], a[i]);
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
ans = max(ans, dp[i]);
}
cout << sum - ans + ans * c << endl;
system("pause");
return 0;
}
for (int i = 1; i <= n; i++)
{
dp[i] = min(dp[i - 1] + a[i], a[i]);
}
int ans=0;
for(int i=1;i<=n;i++)
{
ans=min(ans,dp[i]);
}
cout<<sum-ans+ans*c<<endl;
system("pause");
return 0;
}