Submission #920369

# Submission time Handle Problem Language Result Execution time Memory
920369 2024-02-02T13:45:53 Z H1H Stove (JOI18_stove) C++17
100 / 100
17 ms 2508 KB
#include<bits/stdc++.h>
#define T "Task"
using namespace std;

int n, k;
vector<int> a;
vector<int> d;

void ip(){
    cin >> n >> k;
    for(int i = 0; i < n; ++i){
        int a1; cin >> a1;
        a.push_back(a1);
        if(i > 0)d.push_back(a1 - a[i-1]-1);
    }
    sort(d.begin(), d.end());\
    int id = 0;
    long long ans = n;
    k -= n;
    while(k < 0){
        ans += d[id];
        ++id; ++k;
    }
    cout << ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(T".INP", "r")){
        freopen(T".INP", "r", stdin);
        freopen(T".OUT", "w", stdout);
    }
    int tt = 1;
//    cin >> tt;
    while(tt--){
        ip();
    }
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:31:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |         freopen(T".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
stove.cpp:32:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |         freopen(T".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 15 ms 2260 KB Output is correct
17 Correct 17 ms 2264 KB Output is correct
18 Correct 15 ms 2508 KB Output is correct
19 Correct 15 ms 2252 KB Output is correct
20 Correct 15 ms 2440 KB Output is correct
21 Correct 16 ms 2260 KB Output is correct
22 Correct 16 ms 2352 KB Output is correct
23 Correct 14 ms 2260 KB Output is correct
24 Correct 15 ms 2264 KB Output is correct