Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.io.OutputStreamWriter;
  6.  
  7. public class Main{
  8. public static int max(int a, int b) {
  9. if(a>=b) return a;
  10. else return b;
  11. }
  12. public static void main(String args[]) throws IOException{
  13. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  14. BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
  15.  
  16. int cass = Integer.parseInt(br.readLine());
  17.  
  18. String pp[] = br.readLine().split(" ");
  19. int[] ppp = new int[cass+1];
  20. for(int i=0;i<cass;i++) {
  21. ppp[i+1] = Integer.parseInt(pp[i]);
  22. }
  23.  
  24. int[] arr = new int[cass+1];
  25. arr[0] = 0;
  26. arr[1] = ppp[1];
  27.  
  28. for(int i=2;i<cass+1;i++){
  29. int maax = ppp[i];
  30. for(int j=1;j<(i/2)+1;j++) {
  31. maax = max(arr[j]+arr[i-j],maax);
  32. arr[i] = maax;
  33. }
  34. }
  35.  
  36. bw.write(arr[cass]+"");
  37. bw.flush();
  38. bw.close();
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement