이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const string taskname = "codeforces";
#define FILE 0
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define bit(i, a) (((a)>>(i))&1)
#define ms(a, v) memset(a, v, sizeof(a))
#define lb(a, v) lower_bound(a.begin(), a.end(), v)
#define ub(a, v) upper_bound(a.begin(), a.end(), v)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
typedef vector<bool> vb;
const ll mod = 1e9+7;
const ll maxn = 2e5+13;
const ll inf = 1e9+5;
const ll infl = 1e18+5;
char tochar[] = {'0','1','2','3','4','5','6','7','8','9'};
const bool testcases = true;
const ll maxN=3e5+10;
ll n,a[maxN],k;
priority_queue<ll>pq;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen((taskname+".inp").c_str(), "r", stdin);
//freopen((taskname+".out").c_str(), "w", stdout);
cin >> n >> k;
for(int i=1;i<=n;i++) cin >> a[i];
ll ans=a[n]+1-a[1];
for(int i=1;i<n;i++)
{
pq.push(a[i+1]-a[i]-1);
}
k--;
while(k--)
{
ans-=pq.top();
pq.pop();
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |