제출 #1124820

#제출 시각아이디문제언어결과실행 시간메모리
1124820zentanStove (JOI18_stove)C++17
100 / 100
33 ms1192 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k; cin >> k; vector<int> nums(n); vector<int> spaces(n-1); for(int i = 0; i < n; i++) { cin >> nums[i]; } for(int i = 0; i < n-1; i++) { spaces[i] = nums[i+1] - nums[i] - 1; } sort(spaces.rbegin(), spaces.rend()); //for(auto i : nums) { //cout << i << " " ; //} cout << endl; //for(auto i : spaces) { //cout << i << " " ; //}cout << endl; int ans = nums[n-1] - nums[0] + 1; for(int i = 0; i < k-1; i++) { ans -= spaces[i]; } cout << ans << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...