답안 #587113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587113 2022-07-01T10:39:56 Z proma Stove (JOI18_stove) C++17
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

#define int long long
#define see(x) cout<<#x<<"="<<x<<"\n";
#define endl "\n"

using namespace std;

const int N = 1e5+5;

int n, k, t[N], pos[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
*/

    cin >> n >> k;

    vector <pair <int, int>> stop;
    for (int i = 0; i < n; i ++) {
        cin >> t[i];
    }
    for (int i = 0; i < n; i ++) {
        if (i + 1 < n) {
            stop.push_back({t[i+1] - t[i], i});
        }
    }

    sort(stop.rbegin(), stop.rend());

    for (int i = 0; i < k - 1; i ++) {
        pos[stop[i].second] = 1;
    }

    int flag = 0, res = 0;
    for (int i = 0; i < n; i ++) {
        if (pos[i]) res ++;
        if (i and pos[i-1]) continue;
        res += t[i] - t[i-1];
    }

    cout << res << endl;

    return 0;
}

Compilation message

stove.cpp: In function 'int32_t main()':
stove.cpp:39:9: warning: unused variable 'flag' [-Wunused-variable]
   39 |     int flag = 0, res = 0;
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -