Submission #1047399

# Submission time Handle Problem Language Result Execution time Memory
1047399 2024-08-07T12:30:26 Z lamlamlam Stove (JOI18_stove) C++17
100 / 100
15 ms 3512 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int MN = 1e5+5;
int n,k,a[MN];
vector<int> v;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #define task "troll"
    if(fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
    sort(a+1,a+1+n);
    for(int i=2; i<=n; i++) v.push_back(a[i]-a[i-1]-1);
    sort(v.begin(),v.end());
    int ans = a[n]-a[1]+1;
    k--;
    for(int i=n-2; i>=0; i--){
        if(k==0) break;
        k--;
        ans -= v[i];
    }
    cout << ans;
    cerr << "\nTime: " << 1000.0 * clock() / CLOCKS_PER_SEC << endl;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:15:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(task".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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 408 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 408 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 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 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 472 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 408 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 13 ms 3288 KB Output is correct
17 Correct 15 ms 3192 KB Output is correct
18 Correct 13 ms 3292 KB Output is correct
19 Correct 14 ms 3512 KB Output is correct
20 Correct 12 ms 3292 KB Output is correct
21 Correct 12 ms 3348 KB Output is correct
22 Correct 13 ms 3276 KB Output is correct
23 Correct 15 ms 3292 KB Output is correct
24 Correct 13 ms 3292 KB Output is correct