제출 #156842

#제출 시각아이디문제언어결과실행 시간메모리
156842InfiniteJestStove (JOI18_stove)C++14
100 / 100
91 ms3064 KiB
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>
#include <math.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

ifstream in("input.txt");
ofstream out("output.txt");

typedef long long ll;

int n,k;
ll v[100001];
ll tot=0;
ll diff[100001];

bool cmp(int a, int b){
  return a>b;
}

int main(){
  cin>>n>>k;
  v[0]=-1e9-1;
  cin>>v[0];
  for(int i=1;i<=n-1;i++){
    cin>>v[i];
    tot+=v[i]-v[i-1];
    diff[i]=v[i]-v[i-1];
  }
  sort(diff+1,diff+n,cmp);
  for(int i=1;i<=k-1;i++){
    tot-=diff[i]-1;
  }
  //if(k>=2&&v[1]-v[0]<diff[k-1])tot+=1;
  tot+=1;

  cout<<tot;

}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…