답안 #1049761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1049761 2024-08-09T04:47:45 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
41 ms 1480 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 60 * 10000
void solve() {
    int n,k;
    cin >> n >> k;
    vector <int> a(n);
    vector <int> b;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        b.push_back(a[i+1] - a[i]);
    } sort(b.begin(),b.end());
   
    if (k == 1) {
        cout << a[n - 1] - a[0] + 1;
        return;
    } else if (n == k) {
        cout << n ;
        return;
    }
    int ans1 = a[n - 1] -a[0] + 1;
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans += b[i] + 1;
         k--;
         if (n - (i + 1)*2 <= k) {
             ans += k;
             break;
         } 
    } cout << ans;
}
int main()
{
    solve();
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:22:9: warning: unused variable 'ans1' [-Wunused-variable]
   22 |     int ans1 = a[n - 1] -a[0] + 1;
      |         ^~~~
# 결과 실행 시간 메모리 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 0 ms 348 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 0 ms 348 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 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 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 0 ms 348 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 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 31 ms 1240 KB Output is correct
17 Correct 24 ms 1468 KB Output is correct
18 Correct 24 ms 1472 KB Output is correct
19 Correct 26 ms 1476 KB Output is correct
20 Correct 24 ms 1240 KB Output is correct
21 Correct 24 ms 1208 KB Output is correct
22 Correct 25 ms 1480 KB Output is correct
23 Correct 41 ms 1228 KB Output is correct
24 Correct 24 ms 1240 KB Output is correct