#include <iostream>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#define int long long
#define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#define pb push_back
#define ep emplace_back
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_multiset;
const int sz = 3e5+9;
const int MOD = 1e9+7;
const int INF = 1e18;
int a[sz];
int n,k;
void solve()
{
cin>>n>>k;
--k;
vector<int>v;
for (int i = 1; i <= n; ++i)
{
cin>>a[i];
if (i > 1) v.ep(max(0LL,(a[i]-(a[i-1]+1))));
//cerr<<"emplaced: "<<(max(0LL,(a[i]-(a[i-1]+1))))<<'\n';
}
sort(all(v));
int res = a[n];
while(!v.empty() && k)
{
res -= v.back();
//cerr<<"pop: "<<(int)v.back()<<'\n';
v.pop_back();
--k;
}
cout<<res<<'\n';
}
signed main()
{
$AzH_TxdmN$
int t = 1;
//cin>>t;
while (t--)
{
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |