// IN THE NAME OF ALLAH
// YA IMAM REZA
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define wall cerr << "------------------------------------" << endl
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define all(x) x.begin() , x.end()
#define int ll
#define kids int tm = (tl + tr)>>1; int cl = v<<1; int cr = v<<1|1
#define test int n;cin >> n;while(n--)
#define file freopen("input.txt" , "r" , stdin); freopen("output.txt" , "w" , stdout)
#define debug while(1) cout << "TEST\n"
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef pair<int , int> pii;
typedef pair<ll , ll> pll;
typedef pair<pii,int> piii;
typedef pair<pll , ll> plll;
const int N = 1e5+10;
const int K = 400+10;
const ll mod = 1e9+7;
const ll INF = 1e9+10;
const int P = 31;
const int lg = 25;
const int delta = 30103;
int has;
int t[N];
int n , k;
void solve() {
cin >> n >> k;
for(int i = 1 ; i <= n ; i++)
cin >> t[i];
has = t[n] + 1 - t[1];
set<pii> s;
for(int i = 2 ; i <= n ; i++)
s.insert({t[i-1] - t[i] + 1 , i});
for(int i = 1 ; i <= k-1 ; i++) {
auto x = *s.begin();
// cout << x.S << "\n";
s.erase(s.begin());
has += x.F;
}
cout << has << "\n";
}
signed main()
{
fast;
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
604 KB |
Output is correct |
14 |
Correct |
1 ms |
604 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
34 ms |
7764 KB |
Output is correct |
17 |
Correct |
34 ms |
8020 KB |
Output is correct |
18 |
Correct |
33 ms |
8020 KB |
Output is correct |
19 |
Correct |
34 ms |
8024 KB |
Output is correct |
20 |
Correct |
35 ms |
8276 KB |
Output is correct |
21 |
Correct |
35 ms |
8028 KB |
Output is correct |
22 |
Correct |
34 ms |
8036 KB |
Output is correct |
23 |
Correct |
34 ms |
8032 KB |
Output is correct |
24 |
Correct |
33 ms |
8112 KB |
Output is correct |