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:31:52
2017-05-27 12:24:43
2017-05-27 12:18:26
2017-05-27 12:16:39
Task:Jonnesort
Sender:IOG
Submission time:2017-05-27 12:31:52
Status:READY
Result:ACCEPTED

Show test data

Code

#include <bits/stdc++.h>

using namespace std;

int main(void)
{
 cin.sync_with_stdio(0);
 cin.tie(0);
 int n = 0, k = 0;
 cin >> n >> k;
 vector<long> arr(n);
 for (int i = 0; i < n; i++)
 {
        cin >> arr[i];
 }
 vector<long> arr2(arr);
 sort(arr2.begin(), arr2.end());
 
 int maxdist = 999999;
 
 for (unsigned int i = 0; i < arr.size(); ++i)
 {
     auto ptr = lower_bound(arr2.begin(), arr2.end(), arr[i]);
     
     //if (ptr)
     {
         int idx = ptr - arr2.begin();
         
         //cout << "arr[i] " << arr[i] << "\n";
         //cout << "idx " << idx << "\n";
         
         int dist = idx - (int)i;
         
         //cout << "dist " << dist << "\n";
         
         if (dist < maxdist)
            maxdist = dist;
         
         //cout << "maxd " << maxdist << "\n\n";
     }
 
     
 }
 
 // cout << "maxd " << maxdist << "\n";
 
 float resf = (float) abs(maxdist) / (float) (k-1);
 int res = ceil(resf) + 1;
 
 cout << res << endl;
     
}