Submission #724568

#TimeUsernameProblemLanguageResultExecution timeMemory
724568browntoadStove (JOI18_stove)Java
100 / 100
792 ms23596 KiB
import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class stove { public static void main(String[] args){ Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); int K = scanner.nextInt(); ArrayList<Integer> times = new ArrayList<>(); for (int i = 0; i < N; i++) { int arrival = scanner.nextInt(); times.add(arrival); } int length = times.get(N-1) + 1 - times.get(0); ArrayList<Integer> diffTimes = new ArrayList<>(); for (int i=1; i < times.size(); i++) { diffTimes.add(times.get(i) - times.get(i-1) - 1); } Collections.sort(diffTimes); int sum = 0; for (int i = N-K; i < N-1; i++) { sum += diffTimes.get(i); } System.out.println(length - sum); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...