Submission #966960

# Submission time Handle Problem Language Result Execution time Memory
966960 2024-04-20T17:42:12 Z TheSumuraz Stove (JOI18_stove) C++17
100 / 100
56 ms 5316 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int const siz = 100002;
signed main() {
    int n,k;
    cin>>n>>k;
    int a[n+1];
    vector<pair<int,int>>v;
    v.push_back({1e10,1});
    for (int i = 1; i<=n; i++) {
        cin>>a[i];
        if (i>=2) {
            v.push_back({a[i]-a[i-1],i});
        }
    }
    vector<int>ind;
    sort(v.rbegin(),v.rend());
    for (int i = 0; i<k; i++) {
        ind.emplace_back(v[i].second);
    }
    long long cem = 0,point = 1;
    sort(ind.begin(),ind.end());
    for (int i = 0; i<ind.size()-1; i++) {
        while (ind[i]+1!=ind[i+1]) {
            ind[i]++;
        }
        cem+=a[ind[i]]-a[point]+1;
        point = ind[i]+1;
    }
    cem+=a[n]-a[point]+1;
    cout<<cem;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:24:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for (int i = 0; i<ind.size()-1; i++) {
      |                     ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 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 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 436 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 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 604 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 37 ms 4132 KB Output is correct
17 Correct 37 ms 4044 KB Output is correct
18 Correct 37 ms 4036 KB Output is correct
19 Correct 38 ms 4200 KB Output is correct
20 Correct 45 ms 4664 KB Output is correct
21 Correct 47 ms 5228 KB Output is correct
22 Correct 45 ms 5316 KB Output is correct
23 Correct 56 ms 5312 KB Output is correct
24 Correct 44 ms 5316 KB Output is correct