import java.util.Arrays;
import java.util.Scanner;
public class sia {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int areal = s.nextInt();
int harvestCount = s.nextInt();
int[] growthSpeed = new int[areal];
for (int i = 0; i < areal; i++) {
growthSpeed[i] = s.nextInt();
}
Arrays.sort(growthSpeed);
long[] heights = new long[areal];
long prevDay = 0;
for (int i = 0; i < harvestCount; i++) {
long day = s.nextLong();
long harvestHeight = s.nextLong();
long harvest = 0;
for (int j = 0; j < areal; j++) {
long heightForAre = (heights[j] + growthSpeed[j] * (day-prevDay));
if (heightForAre <= harvestHeight) {
heights[j] = heightForAre;
} else {
heights[j] = harvestHeight;
harvest += heightForAre - harvestHeight;
}
}
prevDay = day;
System.out.println(harvest);
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import java.util.Arrays; import java.util.Scanner; public class sia { public static void main(String[] args) { Scanner s = new Scanner(System.in); int areal = s.nextInt(); int harvestCount = s.nextInt(); int[] growthSpeed = new int[areal]; for (int i = 0; i < areal; i++) { growthSpeed[i] = s.nextInt(); } Arrays.sort(growthSpeed); long[] heights = new long[areal]; long prevDay = 0; for (int i = 0; i < harvestCount; i++) { long day = s.nextLong(); long harvestHeight = s.nextLong(); long harvest = 0; for (int j = 0; j < areal; j++) { long heightForAre = (heights[j] + growthSpeed[j] * (day-prevDay)); if (heightForAre <= harvestHeight) { heights[j] = heightForAre; } else { heights[j] = harvestHeight; harvest += heightForAre - harvestHeight; } } prevDay = day; System.out.println(harvest); } } } |
English