-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarn1.cpp
More file actions
49 lines (41 loc) · 880 Bytes
/
barn1.cpp
File metadata and controls
49 lines (41 loc) · 880 Bytes
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
49
/*
ID: dswei191
LANG: C++
TASK: barn1
*/
#include <iostream>
#include <fstream>
#include<vector>
#include <sstream>
#include <algorithm>
using namespace std;
ofstream fout( "barn1.out");
ifstream fin("barn1.in");
int M,S,C;
vector<int> vec;
int main(){
fin >> M >> S >> C;
int t;
for(int i = 0; i < C; i++){
fin >> t;
vec.push_back(t);
}
sort(vec.begin(), vec.end());
int total = vec[vec.size()-1] - vec[0] + 1;
vector<int> tvec;
int base = vec[0];
for(int i = 1; i < vec.size(); i++){
if(base + 1 == vec[i]){
base = vec[i];
}else{
tvec.push_back(vec[i] - base - 1);
base = vec[i];
}
}
sort(tvec.begin(), tvec.end());
for(int i = tvec.size() - 1; i >= 0 && M> 1; i--, M--){
total -= tvec[i];
}
fout << total <<endl;
return 0;
}