/*#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#pragma ("reroll") */
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pb push_back
#define ins insert
#define F first
#define S second
const int mod = 1e7 + 7,N = 5010,inf = 1e18;
signed main(){
//freopen("snnfsn.in","r",stdin)
//freopen("snnfsn.out","w",stdout)
std::ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin >> n >> k;
int a[n + 1];
for(int i = 1;i<=n;i++) cin >> a[i];
int b[n + 1]{};
for(int i = 1;i<n;i++){
b[i] = (a[i + 1]) - a[i] - 1;
}
long long ans = n;
sort(b + 1,b + n);
for(int i = 1;i<=n-k;i++){
if(b[i]>0) ans+=b[i];
}
cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp:13:40: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
13 | const int mod = 1e7 + 7,N = 5010,inf = 1e18;
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |