제출 #765971

#제출 시각아이디문제언어결과실행 시간메모리
765971dhanesanjay123Stove (JOI18_stove)C++14
100 / 100
45 ms3500 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define fi first #define se second #define pll pair<ll, ll> #define pb push_back #define bp pop_back #define ades ios_base::sync_with_stdio(false); cin.tie(NULL); ll N, M, a[100010], ans; bool bener[100010]; pair<ll, ll> ada[100010]; int main(){ cin >> N >> M; for(int i = 1; i<= N; i++){ cin >> a[i]; } for(int i = 1; i< N; i++){ ada[i].fi = a[i+1]-a[i]; ada[i].se = i; } sort(ada+1, ada+N); if(N <= M){ // for(int i = 1; i< N; i++){ // if(a[i] == a[i+1]){ // ans++; // } // else{ // ans++; // } // } cout << N << endl; return 0; } for(int i = 1; i<= N-M; i++){ bener[ada[i].se] = true; // cout << ada[i].se << endl; } for(int i = 1; i<= N; i++){ if(bener[i]){ ans += a[i+1]-a[i]; } else{ ans++; } } cout << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...