import java.util.ArrayList; import java.util.List; import java.util.Scanner; /* 4 4 1 2 4 3 1 1 2 2 3 0 4 4 */ public class sia { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int pow = Integer.parseInt(scanner.next()); int mowingsCount = Integer.parseInt(scanner.next()); List<Long> mowingHeightList = new ArrayList<Long>(pow); List<Long> mowingGrow = new ArrayList<Long>(pow); List<Long> resultMowing = new ArrayList<Long>(mowingsCount); for (int i = 0; i < pow; i++){ long grow = Long.parseLong(scanner.next()); mowingHeightList.add(grow); mowingGrow.add(grow); } long step = 0; do { step = Long.parseLong(scanner.next()); long mowingHeight = Long.parseLong(scanner.next()); long mowingResult = 0; for (int i = 0; i < mowingHeightList.size(); i++) { long aLong = mowingHeightList.get(i); if (aLong >= mowingHeight){ mowingHeightList.set(i, mowingHeight + mowingGrow.get(i)); mowingResult += (aLong - mowingHeight); } } resultMowing.add(mowingResult); }while (pow != step); for (Long aLong : resultMowing) { System.out.println(aLong); } } }
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import java.util.ArrayList; import java.util.List; import java.util.Scanner; /* 4 4 1 2 4 3 1 1 2 2 3 0 4 4 */ public class sia { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int pow = Integer.parseInt(scanner.next()); int mowingsCount = Integer.parseInt(scanner.next()); List<Long> mowingHeightList = new ArrayList<Long>(pow); List<Long> mowingGrow = new ArrayList<Long>(pow); List<Long> resultMowing = new ArrayList<Long>(mowingsCount); for (int i = 0; i < pow; i++){ long grow = Long.parseLong(scanner.next()); mowingHeightList.add(grow); mowingGrow.add(grow); } long step = 0; do { step = Long.parseLong(scanner.next()); long mowingHeight = Long.parseLong(scanner.next()); long mowingResult = 0; for (int i = 0; i < mowingHeightList.size(); i++) { long aLong = mowingHeightList.get(i); if (aLong >= mowingHeight){ mowingHeightList.set(i, mowingHeight + mowingGrow.get(i)); mowingResult += (aLong - mowingHeight); } } resultMowing.add(mowingResult); }while (pow != step); for (Long aLong : resultMowing) { System.out.println(aLong); } } } |