forked from tmwilliamlin168/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathG027-B.java
More file actions
42 lines (39 loc) · 952 Bytes
/
Copy pathG027-B.java
File metadata and controls
42 lines (39 loc) · 952 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
import java.io.*;
import java.util.*;
public class Main {
static final Reader in = new Reader();
public static void main(String[] args) {
int n=in.nextInt();
long x=in.nextInt(), ans=Long.MAX_VALUE;
long[] ps = new long[n+1];
for(int i=0; i<n; ++i)
ps[i+1]=ps[i]+in.nextInt();
for(int i=1; i<=n; ++i) {
long ca=2*(ps[n]-ps[n-i])+i*x;
for(int j=0; n-i*j>0; ++j) {
long b=(2*j+3)*(ps[n-i*j]-ps[Math.max(n-i*(j+1), 0)]);
if(Long.MAX_VALUE-b<ca) {
ca=Long.MAX_VALUE;
break;
}
}
ans=Math.min(ca, ans);
}
System.out.println(ans+n*x);
}
static class Reader {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String next() {
while(st==null||!st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch(Exception e) {}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
}