Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.io.IOException;
- public class CableMerchant {
- public static void main(String[] args) throws IOException {
- BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
- String[] temp = sc.readLine().split(" ");
- int[] cables = new int[temp.length];
- for (int i = 0; i < temp.length; i++) {
- cables[i] = Integer.parseInt(temp[i]);
- }
- int cPrice = Integer.parseInt(sc.readLine());
- int connectPrice = cPrice * 2;
- for (int i = 1; i < cables.length; i++) {
- int splits = (i + 1) / 2;
- int start = 0;
- int end = i - 1;
- while (splits > 0) {
- cables[i] = Math.max(cables[i], cables[start++] + cables[end--] - connectPrice);
- splits--;
- }
- }
- System.out.println(Arrays.toString(cables).replaceAll("[\\[\\],]", ""));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement