이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int readint(){
int x=0,f=1; char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int n,k;
ll a[100005],b[100005];
int main(){
n=readint(); k=readint()-1;
for(int i=1;i<=n;i++) a[i]=readint();
for(int i=1;i<=n-1;i++) b[i]=a[i+1]-a[i]-1;
sort(b+1,b+n);
ll sum=a[n]-a[1]+1;
for(int i=n-1;i>=n-k;i--) sum-=b[i];
printf("%lld\n",sum);
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... |