思路
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5;
ll sum[N];
int main(){
int n,k;scanf("%d%d",&n,&k);
for(int i=1,x;i<=n;++i) scanf("%d",&x),sum[i]=sum[i-1]+x;
ll ans=(ll)k*sum[n];
sort(sum+1,sum+n-1+1);
--k;
for(int i=1;k;--k,++i) ans-=sum[i];
printf("%lld\n",ans);
}