ba015e9217 2014-10-04 kinaba: #include <iostream> ba015e9217 2014-10-04 kinaba: #include <sstream> ba015e9217 2014-10-04 kinaba: #include <iomanip> ba015e9217 2014-10-04 kinaba: #include <vector> ba015e9217 2014-10-04 kinaba: #include <string> ba015e9217 2014-10-04 kinaba: #include <map> ba015e9217 2014-10-04 kinaba: #include <set> ba015e9217 2014-10-04 kinaba: #include <algorithm> ba015e9217 2014-10-04 kinaba: #include <numeric> ba015e9217 2014-10-04 kinaba: #include <iterator> ba015e9217 2014-10-04 kinaba: #include <functional> ba015e9217 2014-10-04 kinaba: #include <complex> ba015e9217 2014-10-04 kinaba: #include <queue> ba015e9217 2014-10-04 kinaba: #include <stack> ba015e9217 2014-10-04 kinaba: #include <cmath> ba015e9217 2014-10-04 kinaba: #include <cassert> ba015e9217 2014-10-04 kinaba: #include <tuple> ba015e9217 2014-10-04 kinaba: using namespace std; ba015e9217 2014-10-04 kinaba: typedef long long LL; ba015e9217 2014-10-04 kinaba: typedef complex<double> CMP; ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: class ShoppingSurveyDiv1 { public: ba015e9217 2014-10-04 kinaba: int minValue(int N, int K, vector <int> s) ba015e9217 2014-10-04 kinaba: { ba015e9217 2014-10-04 kinaba: for(int big=0; big<=N; ++big) ba015e9217 2014-10-04 kinaba: if(can(N, K, s, big)) ba015e9217 2014-10-04 kinaba: return big; ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: assert(false); ba015e9217 2014-10-04 kinaba: return -1; ba015e9217 2014-10-04 kinaba: } ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: bool can(int N, int K, vector<int> sb, int BIG) ba015e9217 2014-10-04 kinaba: { ba015e9217 2014-10-04 kinaba: sort(sb.rbegin(), sb.rend()); ba015e9217 2014-10-04 kinaba: assert(sb[K-1] >= BIG); ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: multiset<int, greater<int>> s; ba015e9217 2014-10-04 kinaba: for(auto p: sb) ba015e9217 2014-10-04 kinaba: if(p-BIG > 0) ba015e9217 2014-10-04 kinaba: s.insert(p-BIG); ba015e9217 2014-10-04 kinaba: int total = accumulate(s.begin(), s.end(), 0); ba015e9217 2014-10-04 kinaba: if(total > (K-1)*(N-BIG)) ba015e9217 2014-10-04 kinaba: return false; ba015e9217 2014-10-04 kinaba: if(!s.empty() && *s.begin() > (N-BIG)) ba015e9217 2014-10-04 kinaba: return false; ba015e9217 2014-10-04 kinaba: return true; ba015e9217 2014-10-04 kinaba: } ba015e9217 2014-10-04 kinaba: }; ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: // BEGIN CUT HERE ba015e9217 2014-10-04 kinaba: #include <ctime> ba015e9217 2014-10-04 kinaba: double start_time; string timer() ba015e9217 2014-10-04 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } ba015e9217 2014-10-04 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) ba015e9217 2014-10-04 kinaba: { os << "{ "; ba015e9217 2014-10-04 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) ba015e9217 2014-10-04 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } ba015e9217 2014-10-04 kinaba: void verify_case(const int& Expected, const int& Received) { ba015e9217 2014-10-04 kinaba: bool ok = (Expected == Received); ba015e9217 2014-10-04 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; ba015e9217 2014-10-04 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } ba015e9217 2014-10-04 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); ba015e9217 2014-10-04 kinaba: #define END verify_case(_, ShoppingSurveyDiv1().minValue(N, K, s));} ba015e9217 2014-10-04 kinaba: int main(){ ba015e9217 2014-10-04 kinaba: ba015e9217 2014-10-04 kinaba: CASE(0) ba015e9217 2014-10-04 kinaba: int N = 10; ba015e9217 2014-10-04 kinaba: int K = 2; ba015e9217 2014-10-04 kinaba: int s_[] = {1, 2, 3}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 0; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(1) ba015e9217 2014-10-04 kinaba: int N = 5; ba015e9217 2014-10-04 kinaba: int K = 2; ba015e9217 2014-10-04 kinaba: int s_[] = {1, 2, 3}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 1; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(2) ba015e9217 2014-10-04 kinaba: int N = 4; ba015e9217 2014-10-04 kinaba: int K = 4; ba015e9217 2014-10-04 kinaba: int s_[] = {4, 4, 4, 2}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 2; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(3) ba015e9217 2014-10-04 kinaba: int N = 20; ba015e9217 2014-10-04 kinaba: int K = 3; ba015e9217 2014-10-04 kinaba: int s_[] = {1, 10, 3, 4, 8, 15, 3, 16, 18, 2, 7, 3}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 10; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(4) ba015e9217 2014-10-04 kinaba: int N = 4; ba015e9217 2014-10-04 kinaba: int K = 2; ba015e9217 2014-10-04 kinaba: int s_[] = {1, 2, 1, 1, 3, 1, 2, 2, 1, 2, 1}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 2; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(5) ba015e9217 2014-10-04 kinaba: int N = 2; ba015e9217 2014-10-04 kinaba: int K = 3; ba015e9217 2014-10-04 kinaba: int s_[] = {1, 1, 1, 2}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = 1; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(6) ba015e9217 2014-10-04 kinaba: int N = 500; ba015e9217 2014-10-04 kinaba: int K = 1; ba015e9217 2014-10-04 kinaba: int s_[] = {500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = -1; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: CASE(6) ba015e9217 2014-10-04 kinaba: int N = 500; ba015e9217 2014-10-04 kinaba: int K = 500; ba015e9217 2014-10-04 kinaba: int s_[] = {500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500,500}; ba015e9217 2014-10-04 kinaba: vector <int> s(s_, s_+sizeof(s_)/sizeof(*s_)); ba015e9217 2014-10-04 kinaba: int _ = -1; ba015e9217 2014-10-04 kinaba: END ba015e9217 2014-10-04 kinaba: } ba015e9217 2014-10-04 kinaba: // END CUT HERE