Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class CableMerchant {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.  
  9.         int[] cables = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  10.         int cPrice = sc.nextInt();
  11.         int connectPrice = cPrice * 2;
  12.  
  13.         for (int i = 1; i < cables.length; i++) {
  14.             int splits = (i + 1) / 2;
  15.  
  16.             int start = 0;
  17.             int end = i - 1;
  18.             while (splits > 0) {
  19.                 cables[i] = Math.max(cables[i], cables[start++] + cables[end--] - connectPrice);
  20.                 splits--;
  21.             }
  22.         }
  23.  
  24.         System.out.println(Arrays.toString(cables).replaceAll("[\\[\\],]", ""));
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement