Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStreamWriter;
- public class Main{
- public static int max(int a, int b) {
- if(a>=b) return a;
- else return b;
- }
- public static void main(String args[]) throws IOException{
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
- int cass = Integer.parseInt(br.readLine());
- String pp[] = br.readLine().split(" ");
- int[] ppp = new int[cass+1];
- for(int i=0;i<cass;i++) {
- ppp[i+1] = Integer.parseInt(pp[i]);
- }
- int[] arr = new int[cass+1];
- arr[0] = 0;
- arr[1] = ppp[1];
- for(int i=2;i<cass+1;i++){
- int maax = ppp[i];
- for(int j=1;j<(i/2)+1;j++) {
- maax = max(arr[j]+arr[i-j],maax);
- arr[i] = maax;
- }
- }
- bw.write(arr[cass]+"");
- bw.flush();
- bw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement