This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 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 = 5e3+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();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |