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:00:59
2017-05-27 11:57:39
Task:Jonnesort
Sender:Proudly div 2
Submission time:2017-05-27 12:00:59
Status:READY
Result:ACCEPTED

Show test data

Code

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

int main(){
	LL n,k;
	cin >> n >> k;
	vector<LL> v;
	for(int i = 0; i < n; i++){
		LL x; cin >> x;
		v.push_back(x);
	}

	vector<LL> v_sorted = v;
	sort(v_sorted.begin(), v_sorted.end());

	vector<bool> used(n);
	LL worst = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			if(v_sorted[j] == v[i] && used[j] == false){
				used[j] = true;
				worst = max(worst, (LL)(i-j));
				break;
			}
		}
	}
	
	LL ans = worst / (k-1) + 1;
	if(worst % (k-1) != 0) ans++;
	cout << ans << endl;
}