Artifact Content
Not logged in

Artifact a42c7d53ea89e664cadb7608400da1fdc45f9e57


#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 CanidsSeesaw { public:
	vector <int> construct(vector <int> wolf, vector <int> fox, int k)
	{
		partial_sum(wolf.begin(), wolf.end(), wolf.begin());

		vector<pair<int, int>> fox_idx;
		for (int i = 0; i < fox.size(); ++i)
			fox_idx.emplace_back(fox[i], i);

		sort(fox_idx.rbegin(), fox_idx.rend());
		while (point_of(fox_idx, wolf) > k) {
			bool swapped = false;
			for(int i=0; i+1<fox_idx.size(); ++i)
				if (fox_idx[i] > fox_idx[i + 1])
				{
					swap(fox_idx[i], fox_idx[i + 1]);
					swapped = true;
					break;
				}
			if (!swapped)break;
		}

		if (point_of(fox_idx, wolf) == k) {
			vector<int> idx;
			for (auto fi : fox_idx)
				idx.push_back(fi.second);
			return idx;
		}
		return vector<int>();
	}

	int point_of(const vector<pair<int,int>>& fox_idx, const vector<int>& wolf_sum) {
		int score = 0, cur = 0;
		for (int i = 0; i < fox_idx.size(); ++i) {
			cur += fox_idx[i].first;
			if (cur > wolf_sum[i])
				++score;
		}
		return score;
	}
};

// 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 vector <int>& Expected, const vector <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(_, CanidsSeesaw().construct(wolf, fox, k));}
int main(){

CASE(0)
	int wolf_[] = {3,1};
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = {4,2};
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = 1; 
	int __[] = {1, 0 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(1)
	int wolf_[] = {1,3};
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = {4,2};
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = 1; 
	vector <int> _; 
END
CASE(2)
	int wolf_[] = {10,10,10,10,10,10,10,10,10,10};
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = {1,100,1,100,1,100,1,100,1,100};
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = 7; 
	int __[] = {0, 2, 4, 1, 6, 3, 5, 7, 9, 8 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(3)
	int wolf_[] = {10,10,10,10,10,10,10,10,10,10};
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = {1,100,1,100,1,100,1,100,1,100};
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = 4; 
	vector <int> _; 
END
CASE(4)
	int wolf_[] = {2};
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = {1};
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = 0; 
	int __[] = {0 };
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
/*
CASE(5)
	int wolf_[] = ;
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = ;
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = ; 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
CASE(6)
	int wolf_[] = ;
	  vector <int> wolf(wolf_, wolf_+sizeof(wolf_)/sizeof(*wolf_)); 
	int fox_[] = ;
	  vector <int> fox(fox_, fox_+sizeof(fox_)/sizeof(*fox_)); 
	int k = ; 
	int __[] = ;
	  vector <int> _(__, __+sizeof(__)/sizeof(*__)); 
END
*/
}
// END CUT HERE