이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define NACHO {ios::sync_with_stdio(0); cin.tie(NULL);}
typedef long long tint;
const int INF = 50000200;
const int MOD = 1e9+7;
const int N = 100001;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
bool valid(int x, int y, int n, int m){ return (0<=x && x<n && 0<=y && y<m);}
int main(){
NACHO;
int n, k;
cin >> n >> k;
vector<int> t (n);
forn(i, n) cin >> t[i];
vector<int> difs;
forsn(i, 1, n) difs.push_back(t[i]-t[i-1]-1);
sort(rall(difs));
int tot = t.back()-t[0]+1;
forn(i, k-1){
tot-=difs[i];
}
cout << tot << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |