답안 #1017493

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017493 2024-07-09T08:23:40 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
14 ms 3324 KB
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define nemeshay ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define allr(pon) pon.rbegin(), pon.rend()
#define all(pon) pon.begin(), pon.end()
#define nosolve cout << "-1\n"
#define YES cout << "YES\n"
#define Yes cout << "Yes\n"
#define pii pair <int, int>
#define OK cout << "OK\n"
#define Ok cout << "Ok\n"
#define NO cout << "NO\n"
#define No cout << "No\n"
#define pf push_front
#define int long long
#define pb push_back
#define sigma signed
#define sc second
#define fr first
using namespace __gnu_pbds;
using namespace std;
const int N = 1e6 + 20, INF = 1e10 + 7;
int a[N], pref[N];
sigma main(){
    nemeshay
    int n, k, ans;
    cin >> n >> k;
    vector <int> pon;
    for (int i = 0; i < n; i++) cin >> a[i];
    ans = a[n - 1] + 1 - a[0];
    if (k == 1) {
        cout << ans;
        return 0;
    }
    if (k == n) {
        cout << n;
        return 0;
    }
    for (int i = 1; i < n; i++) pon.pb(a[i] - a[i - 1] - 1);
    sort (pon.rbegin(), pon.rend());
    for (int i = 0; i < k -1; i++) ans -= pon[i];
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 524 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 524 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 13 ms 3292 KB Output is correct
17 Correct 13 ms 3288 KB Output is correct
18 Correct 13 ms 3292 KB Output is correct
19 Correct 13 ms 3220 KB Output is correct
20 Correct 14 ms 3292 KB Output is correct
21 Correct 14 ms 3292 KB Output is correct
22 Correct 13 ms 3292 KB Output is correct
23 Correct 13 ms 3292 KB Output is correct
24 Correct 13 ms 3324 KB Output is correct