답안 #875626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
875626 2023-11-20T08:44:13 Z TahirAliyev Stove (JOI18_stove) C++17
0 / 100
0 ms 348 KB
#include <bits/stdc++.h>
using namespace std;


#define ll long long int
#define pii pair<int, int>
#define oo 1e9

const int MAX = 1e5 + 5;

int n, k;
int arr[MAX];
vector<int> v;

int main(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
        arr[i] -= arr[1];
        arr[i]++;
    }
    for(int i = 1; i <= n; i++){
        if(arr[i] - arr[i - 1] - 1 > 0){
            v.push_back(arr[i] - arr[i - 1] - 1);
        }
    }
    if(k >= v.size() + 1){
        cout << n << '\n';
        return 0;
    }
    sort(v.begin(), v.end());
    int ans = n;
    for(int i = 0; i < v.size() + 1 - k; i++){
        ans += v[i];
    }
    cout << ans << '\n';
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:27:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     if(k >= v.size() + 1){
      |        ~~^~~~~~~~~~~~~~~
stove.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for(int i = 0; i < v.size() + 1 - k; i++){
      |                    ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -