Artifact 2a313f584cf9e5c78214a5fa7994cf9e8f2feab0
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <tuple>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class TheConsecutiveIntegersDivOne { public:
int find(vector <int> numbers, int k)
{
sort(numbers.begin(), numbers.end());
int best = 0x7fffffff;
for(int fixed=0; fixed<numbers.size(); ++fixed) {
for(int s=0; s+k<=numbers.size(); ++s) {
if(s<=fixed && fixed<=s+k) {
int cost = 0;
for(int i=0; i<k; ++i)
cost += abs(numbers[s+i] - (numbers[fixed]-(fixed-s-i)));
best = min(best, cost);
}
}
}
return best;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, TheConsecutiveIntegersDivOne().find(numbers, k));}
int main(){
CASE(0)
int numbers_[] = {4, 7, 47};
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = 2;
int _ = 2;
END
CASE(1)
int numbers_[] = {1, 100};
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = 1;
int _ = 0;
END
CASE(2)
int numbers_[] = {-96, -53, 82, -24, 6, -75};
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = 2;
int _ = 20;
END
CASE(3)
int numbers_[] = {64, -31, -56};
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = 2;
int _ = 24;
END
CASE(4)
int numbers_[] = {-96, -53, 82, -24, 6, -75};
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = 4;
int _ = 90;
END
/*
CASE(5)
int numbers_[] = ;
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = ;
int _ = ;
END
CASE(6)
int numbers_[] = ;
vector <int> numbers(numbers_, numbers_+sizeof(numbers_)/sizeof(*numbers_));
int k = ;
int _ = ;
END
*/
}
// END CUT HERE