이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<bool> vb;
ll mod = 1e9 + 7;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(ll i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
using namespace std;
ll ans;
void bfs(vvp64 adj, ll source, ll n, ll choice, vb used, v64 val)
{
queue<p64>q;
// v64 d(n, LLONG_MAX);
q.push(mp(source, LLONG_MAX));
//vb used(n, false);
//d[source] = 0;
used[source] = true;
while(!q.empty())
{
p64 v = q.front();
q.pop();
for(p64 u : adj[v.fi])
{
if(!used[u.fi]){
if(u.se >= choice){
used[u.fi] = true;
//u.se = min(u.se, v.se);
//val[u.fi] = u.se;
q.push(u);
ans++;
}
}
}
}
//ofstream fout("mootube.out");
//fout << ans << '\n';
//return ans;
}
void solve(ll it)
{
ll n, k;
cin >> n >> k;
v64 A(n);
for(ll &x : A) cin >> x;
v64 B;
if(n == 1){
cout << 1 << '\n';
return;
}
FOR(1, n - 1, i)
{
B.pb(A[i] - A[i - 1] - 1);
}
sort(rall(B));
ll j = min((ll)B.size(), k - 1), ans = 0;
for(int i = 0; i < j; i++)
{
ans += B[i];
}
cout << A[n - 1] - ans << '\n';
}
int main()
{
/*#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif*/
fast_cin();
ll t = 1;
//cin >> t;
for(int it=1; it<=t; it++)
{
// cout << "Case #" << it+1 << ": ";
solve(it);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |