답안 #1112272

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112272 2024-11-14T01:26:52 Z Matbubble Stove (JOI18_stove) C++14
0 / 100
1 ms 336 KB
#include <iostream>
#include <iomanip>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;
#define dbg(x) cerr<<#x<<": "<<x<<"\n";

/*  
I love DP
*/

const int maxN=1e5;
int arr[maxN+1];

void solve(){
    int n, k; cin>>n>>k;
    for(int i=0 ; i<n ; i++) cin>>arr[i];
    int ans=arr[n-1];
    vector<int>v;
    for(int i=0 ; i<n-1 ; i++){
        v.push_back(arr[i+1]-1-arr[i]);
    }
    sort(v.begin(), v.end(), greater<int>());
    for(int i=0 ; i<min(k-1, (int)v.size()) ; i++) ans-=v[i];
    cout<<ans<<"\n";
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -