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:19:02
Task:Jonnesort
Sender:Game of Nolife
Submission time:2017-05-27 11:19:02
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

ll xs [1010];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> xs[i];
	}
	int round = 0;
	while (1) {
		bool changed = false;
		for (int i = 0; i <= n - k; i++) {
			for (int j = 0; j < k - 1; j++) {
				if (xs[i + j] > xs[i + j + 1]) {
					changed = true;
				}
			}
			sort(xs + i, xs + i + k);
		}
		round++;
		if (!changed) {
			break;
		}
	}
	cout << round << "\n";
}