답안 #966819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966819 2024-04-20T12:16:04 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
53 ms 5448 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++) {
      |                     ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 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 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 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 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 344 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 604 KB Output is correct
16 Correct 38 ms 4300 KB Output is correct
17 Correct 38 ms 4044 KB Output is correct
18 Correct 37 ms 4036 KB Output is correct
19 Correct 40 ms 4232 KB Output is correct
20 Correct 41 ms 4540 KB Output is correct
21 Correct 44 ms 5340 KB Output is correct
22 Correct 53 ms 5448 KB Output is correct
23 Correct 44 ms 5308 KB Output is correct
24 Correct 44 ms 5308 KB Output is correct