Submission #377322

#TimeUsernameProblemLanguageResultExecution timeMemory
377322timg8710Stove (JOI18_stove)Java
100 / 100
490 ms18112 KiB
// package olypmiads; import java.io.*; import java.util.*; @SuppressWarnings("unchecked") public class stove { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); StringTokenizer st = new StringTokenizer(br.readLine()); int N = Integer.parseInt(st.nextToken()); int K = Integer.parseInt(st.nextToken())-1; List<Integer> gaps = new ArrayList(); int c = Integer.parseInt(br.readLine()); int ret = 1; for(int i = 0; i<N-1; i++){ int n = Integer.parseInt(br.readLine()); gaps.add(n - c - 1); ret += n - c; c = n; } Collections.sort(gaps, Collections.reverseOrder()); for(int i = 0; i<Math.min(K, gaps.size()); i++) ret -= gaps.get(i); pw.println(ret); pw.close(); br.close(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...