Code Submission Evaluation System Login

CSES - HIIT Open 2017

HIIT Open 2017

Contest start:2017-05-27 11:00:00
Contest end:2017-05-27 16:00:00

Task list | Submit code | Submissions | Messages | Scoreboard


History
2017-05-27 11:51:20
Task:Jonnesort
Sender:Nää jäbät
Submission time:2017-05-27 11:51:20
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <set>

const int N = 1e3;
int nums [N];

int main() {
        int n, k;
        std::cin >> n >> k;
        for (int i = 0; i < n; ++i) {
            std::cin >> nums[i];
        }
        std::multiset<int> help;
        int c = 1;
        bool stop = false;
        while(! stop) {
            stop = true;
            for (int j = 0; j < k; ++j) {
                help.insert(nums[j]);
            }
            for (int j = 0; j + k < n; ++j) {
                auto it = help.begin();
                int val = *it;
                help.erase(it);
                if (nums[j] != val) {
                    stop = false;
                }
                nums[j] = val;
                help.insert(nums[j+k]);
            }
            for (int j = n - k; j < n; ++j) {
                    auto it = help.begin();
                    int val = *it;
                    help.erase(it);
                    if (nums[j] != val) {
                        stop = false;
                    }
                    nums[j] = val;
            }
            if (! stop) {
                    ++c;
            }
        }
        std::cout << c << '\n';
}