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 12:29:53
Task:Jonnesort
Sender:HIIT AND RUN
Submission time:2017-05-27 12:29:53
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;


vector<ll> v;


int main() {
    ios_base::sync_with_stdio(0);
    
    
    ll n, k;
    cin >> n >> k;
    v.resize(n);
    
    for(int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        v[i] = x;
    }
    
    ll rounds = 1; 
    
    for(;;) {
        bool ok = false;
        for(int i = 1; i < n; i++) {
            if (v[i-1] > v[i]) ok = true;
        }
        
        if (!ok) break;
        
        for(int i = 0; i <= n-k; i++) {
            sort(v.begin() + i, v.begin() + i + k);
            
            //for(int i = 0; i < n; i++) {
            //    cout << v[i] << " ";
            //}
            //cout << endl;
        }
        
    
        rounds++;
        
    }
    
    cout << rounds << endl;
    
    
}