제출 #792417

#제출 시각아이디문제언어결과실행 시간메모리
792417vjudge1Stove (JOI18_stove)C++17
100 / 100
20 ms1384 KiB
#include <bits/stdc++.h>

#define fi first
#define se second

const int N = 100100;


using namespace std;


int n;
int k;
int a[N];
vector < int > v;

int main()
{
    #ifdef zxc
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);


    cin >> n >> k;
        long long ans = 0;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        sort(a + 1, a + n + 1);
        for(int i = 2; i <= n; i++){
                ans += a[i] - a[i - 1];
                v.push_back(a[i] - a[i - 1]);
        }
        sort(v.begin(), v.end());
        while(v.size() > n - k){
                ans -= v.back();
                v.pop_back();
        }
        cout << ans + k << "\n";

}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'int main()':
stove.cpp:37:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   37 |         while(v.size() > n - k){
      |               ~~~~~~~~~^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...