Submission #540220

# Submission time Handle Problem Language Result Execution time Memory
540220 2022-03-19T16:47:20 Z lynnetan Stove (JOI18_stove) C++17
0 / 100
1 ms 340 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


struct number {
    int num, diff;

    number(int n) {
        num = n;
    }
};

bool compareNum(number n1, number n2) {
    return n1.num <= n2.num;
}

bool compareDiff(number n1, number n2) {
    return n1.diff <= n2.diff;
}

int countDiff(number n1, number n2) {
    return n2.num - n1.num;
}


int main() {
    int n, k, inputNum;
    cin >> n >> k;

    vector<number> arr;

    for(int i = 0; i < n; i++) {
        cin >> inputNum;
        arr.push_back(number(inputNum));
    }

    sort(arr.begin(), arr.end(), compareNum);


    if(k < n) {
        for(int i = 1; i < n; i++) {
            arr[i].diff = countDiff(arr[i-1], arr[i]);
        }

        sort(arr.begin(), arr.end(), compareDiff);

        int sum = n;

        
        int x = n - k + 1;
        for (int i = 1; i < x; i++) {
            sum += arr[i].diff - 1;
        }

        cout << sum;

    } else {
        cout << n;
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Runtime error 1 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Runtime error 1 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Runtime error 1 ms 340 KB Execution killed with signal 11
9 Halted 0 ms 0 KB -