#include<bits/stdc++.h>
#define forin(i,a,b) for(int i = a; i <= b;i++)
#define forde(i,a,b) for(int i = a; i >= b;i--)
#define re(i,a,b) for(int i = a; i < b; i++)
#define forv(a,b) for(auto & a : b)
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define fi first
#define se second
#define pb push_back
#define int long long
#define getbit(x,i) ((x >> i) & 1)
using namespace std;
const int N = 1e5 + 10;
int t[N],res[N-1];
int n,k,ans;
signed main()
{
cin.tie(0) -> sync_with_stdio(0);
if(fopen("task.cpp","r"))
{
freopen("task.cpp","r",stdin);
freopen("wa.cpp","w",stdout);
}
cin >> n >> k;
k = n - k;
forin(i,1,n) cin >> t[i];
re(i,1,n) res[i] = t[i+1] - t[i] - 1;
sort(res + 1, res + n);
ans = n;
forin(i,1,k)
{
ans += res[i];
}
cout << ans;
}
Compilation message
stove.cpp: In function 'int main()':
stove.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen("task.cpp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen("wa.cpp","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
14 ms |
1836 KB |
Output is correct |
17 |
Correct |
14 ms |
1800 KB |
Output is correct |
18 |
Correct |
14 ms |
1880 KB |
Output is correct |
19 |
Correct |
14 ms |
1876 KB |
Output is correct |
20 |
Correct |
14 ms |
1884 KB |
Output is correct |
21 |
Correct |
14 ms |
1876 KB |
Output is correct |
22 |
Correct |
17 ms |
1888 KB |
Output is correct |
23 |
Correct |
14 ms |
1876 KB |
Output is correct |
24 |
Correct |
14 ms |
1888 KB |
Output is correct |