import java.util.Scanner;
import java.util.Arrays;
public class a_planting_trees {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int length = in.nextInt();
int minTime = 0;
Integer treeArray[] = new Integer[length];
for (int i = 0; i < length; i++) {
treeArray[i] = in.nextInt();
}
Arrays.sort(treeArray);
int day = 1;
for (int i = length - 1; i >= 0; i--) {
// System.out.println(day);
if (day + treeArray[i] > minTime) {
minTime = day + treeArray[i];
}
day++;
}
// System.out.println(Arrays.toString(treeArray));
System.out.println(minTime + 1);
}
}
2
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class g_platforms {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int platfNum = in.nextInt();
int platfHeights[] = new int[platfNum];
long wastedEnergy[] = new long[platfNum];
// An array that stores info: Ypu come to platform j from arr[j]
int whereFrom[] = new int[platfNum];
whereFrom[0] = Integer.MIN_VALUE;
// To store path(synamic because path cam be smaller)
List<Integer> path = new ArrayList<Integer>();
for (int i = 0; i < platfNum; i++) {
platfHeights[i] = in.nextInt();
}
wastedEnergy[0] = 0;
wastedEnergy[1] = Math.abs(platfHeights[1] - platfHeights[0]);
long megaJump, normalJump;
for (int i = 2; i < platfNum; i++) {
megaJump = wastedEnergy[i-2] + 3 * Math.abs(platfHeights[i] - platfHeights[i-2]);
normalJump = wastedEnergy[i-1] + Math.abs(platfHeights[i] - platfHeights[i-1]);
if (megaJump < normalJump) {
wastedEnergy[i] = megaJump;
whereFrom[i] = i - 2;
} else {
wastedEnergy[i] = normalJump;
whereFrom[i] = i - 1;
}
}
// We start getting the path len and path itself, start by default from last elem.
int fromIdx = platfNum - 1;
path.add(fromIdx + 1);
int pathPlatfAmount = 1;
while (whereFrom[fromIdx] != Integer.MIN_VALUE) {
fromIdx = whereFrom[fromIdx];
pathPlatfAmount++;
path.add(fromIdx + 1);
}
// Results
System.out.println(wastedEnergy[platfNum - 1]);
System.out.println(pathPlatfAmount);
for (int i = path.size() - 1; i >= 0; i--) {
System.out.print(path.get(i) + " ");
}
}
}
3
import java.util.Arrays;
import java.util.Scanner;
public class ICandyStore {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// Main Loop
while (true) {
int candyNum = in.nextInt();
int totalMoney = (int)(in.nextDouble() * 100);
// the ONLY Break Case
if (candyNum == 0) {
break;
}
int calories[] = new int[candyNum];
int cost[] = new int[candyNum];
// Input management
for (int i = 0; i < candyNum; i++) {
calories[i] = in.nextInt();
cost[i] = (int)(in.nextDouble() * 100);
}
int caloriesForPrices[] = new int[totalMoney + 1];
for (int i = 0; i < candyNum; i++) {
for (int j = cost[i]; j < totalMoney + 1; j++) {
int caloriesForPrice = caloriesForPrices[j - cost[i]] + calories[i];
if (caloriesForPrice > caloriesForPrices[j]) {
caloriesForPrices[j] = caloriesForPrice;
}
}
}
System.out.println(caloriesForPrices[totalMoney]);
}
}
}
4
line = input().split()
width = int(line[0])
l = int(line[1])
river = input().split()
for i in range(len(river)):
river[i] = int(river[i])
sum = 0
for i in range(l):
sum += river[i]
i+=1
minim = sum
for i in range(l, width-1):
sum = sum - river[i-l] + river[i]
minim = min(minim, sum)
print(minim)