#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename A>
void __print(const A &x);
template <typename A, typename B>
void __print(const pair<A, B> &p);
template <typename... A>
void __print(const tuple<A...> &t);
template <typename T>
void __print(stack<T> s);
template <typename T>
void __print(queue<T> q);
template <typename T, typename... U>
void __print(priority_queue<T, U...> q);
template <typename A>
void __print(const A &x) {
bool first = true;
cerr << '{';
for (const auto &i : x) {
cerr << (first ? "" : ","), __print(i);
first = false;
}
cerr << '}';
}
template <typename A, typename B>
void __print(const pair<A, B> &p) {
cerr << '(';
__print(p.first);
cerr << ',';
__print(p.second);
cerr << ')';
}
template <typename... A>
void __print(const tuple<A...> &t) {
bool first = true;
cerr << '(';
apply([&first](const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
cerr << ')';
}
template <typename T>
void __print(stack<T> s) {
vector<T> debugVector;
while (!s.empty()) {
T t = s.top();
debugVector.push_back(t);
s.pop();
}
reverse(debugVector.begin(), debugVector.end());
__print(debugVector);
}
template <typename T>
void __print(queue<T> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.front();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
template <typename T, typename... U>
void __print(priority_queue<T, U...> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.top();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail>
void _print(const Head &H, const Tail &...T) {
__print(H);
if (sizeof...(T))
cerr << ", ";
_print(T...);
}
#ifndef ONLINE_JUDGE
#define debug(...) cerr << "Line:" << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define debug(...)
#endif
#define int long long
char buf[1<<23],*p1=buf,*p2=buf;
#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
inline int rd()
{
int s=0;
char ch=getchar(),last;
while(ch<'0'||ch>'9') last=ch,ch=getchar();
while(ch>='0'&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar();
return last=='-'?-s:s;
}
int num[100];
inline void rt(int x)
{
if(x<0) putchar('-'),x=-x;;
int len=0;
do num[len++]=x%10;while(x/=10);
while(len--) putchar(num[len]+'0');
}
void solve(){
int n,k; cin>>n>>k;
vector<int>t(n);
vector<pair<int,int>> seg;
for(int i=0;i<n;i++){
cin>>t[i];
seg.push_back(make_pair(t[i],t[i]+1));
}
sort(seg.begin(),seg.end());
vector<int> mn;
for(int i=1;i<n;i++){
mn.push_back(seg[i].fi-seg[i-1].se);
}
sort(mn.begin(),mn.end());
int ans=0;
for(int i=0;i<n-k;i++) ans+=mn[i];
cout<<ans+n<<'\n';
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
324 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
468 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
21 ms |
5380 KB |
Output is correct |
17 |
Correct |
23 ms |
5480 KB |
Output is correct |
18 |
Correct |
20 ms |
5372 KB |
Output is correct |
19 |
Correct |
22 ms |
5364 KB |
Output is correct |
20 |
Correct |
21 ms |
5372 KB |
Output is correct |
21 |
Correct |
21 ms |
5452 KB |
Output is correct |
22 |
Correct |
24 ms |
5360 KB |
Output is correct |
23 |
Correct |
21 ms |
5428 KB |
Output is correct |
24 |
Correct |
21 ms |
5424 KB |
Output is correct |