답안 #1112276

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112276 2024-11-14T01:47:10 Z Matbubble Stove (JOI18_stove) C++14
100 / 100
17 ms 3296 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 long long maxN=2e5;
long long arr[maxN+1];

void solve(){
    long long n, k; cin>>n>>k;
    for(long long i=0 ; i<n ; i++) cin>>arr[i];
    long long ans=arr[n-1]-arr[0]+1;
    vector<long long>v;
    for(long long i=0 ; i<n-1 ; i++){
        v.push_back(arr[i+1]-1-arr[i]);
    }
    sort(v.begin(), v.end(), greater<long long>());
    for(long long i=0 ; i<k-1; 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 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 484 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 2 ms 336 KB Output is correct
13 Correct 2 ms 336 KB Output is correct
14 Correct 1 ms 484 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 15 ms 3280 KB Output is correct
17 Correct 15 ms 3280 KB Output is correct
18 Correct 16 ms 3280 KB Output is correct
19 Correct 15 ms 3024 KB Output is correct
20 Correct 16 ms 3292 KB Output is correct
21 Correct 17 ms 3280 KB Output is correct
22 Correct 15 ms 2256 KB Output is correct
23 Correct 15 ms 3024 KB Output is correct
24 Correct 15 ms 3296 KB Output is correct