1. /*
  2.   FORHAD-SUST-BD
  3. */
  4. #include <iostream>
  5. #include <string>
  6. #include <map>
  7. #include <queue>
  8. #include <stack>
  9. #include <algorithm>
  10. #include <list>
  11. #include <set>
  12. #include <cmath>
  13. #include <cstring>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <sstream>
  17. #include <stdlib.h>
  18. #include <vector>
  19. #include <iomanip>
  20.  
  21. using namespace std;
  22.  
  23. #ifdef __GNUC__
  24. typedef long long ll;typedef unsigned long long ull;
  25. #else
  26. typedef __int64 ll; typedef unsigned __int64 ull;
  27. #endif
  28.  
  29. #define INF 1<<28
  30. #define SIZE 55
  31. #define PI 2*acos(0)
  32. #define fg %I64d
  33. #define REP(i,n) for (i=0;i<n;i++)
  34. #define REV(i,n) for (i=n;i>=0;i--)
  35. #define FOR(i,p,k) for (i=p; i<k;i++)
  36. #define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
  37.  
  38. #define bug(x) cout<< "->" <<#x<<": "<<x<<endl
  39. #define Sort(x) sort(x.begin(),x.end())
  40. #define Reverse(x) reverse(x.begin(),x.end())
  41. #define MP(a,b) make_pair(a,b)
  42. #define Clear(x,with) memset(x,with,sizeof(x))
  43. #define Copy(c,r) memcpy(c,r,sizeof(r))
  44. #define SZ(x) (int)x.size()
  45. #define length(x) (int)x.length()
  46. #define All(x) x.begin(),x.end()
  47. #define pb push_back
  48. #define popcount(i) __builtin_popcount(i)
  49. #define gcd(a,b) __gcd(a,b)
  50. #define fs first
  51. #define sc second
  52. #define two(X) (1<<(X))
  53. #define twoL(X) (((int64)(1))<<(X))
  54. #define contain(S,X) (((S)&two(X))!=0)
  55. #define containL(S,X) (((S)&twoL(X))!=0)
  56.  
  57. typedef pair<int,int> pii;
  58. typedef pair<double,double> pdd;
  59. typedef vector<int> vi;
  60. typedef vector<double>vd;
  61. typedef vector<ll>vll;
  62. typedef vector<string> vs;
  63. typedef vector<vi>vvi;
  64. typedef vector<vll>vvll;
  65. typedef vector<vd>vvd;
  66. typedef vector<pii>vpii;
  67. typedef map<string,int> msi;
  68. typedef map<int,int>mii;
  69. typedef map<pii,int>mpi;
  70.  
  71. template<class T> inline T sqr(T x){return x*x;}
  72. template<class T> inline bool isPrime(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
  73. template<class T> inline T Mod(T n,T m) {return (n%m+m)%m;} //For Positive Negative No.
  74. template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
  75. int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
  76. ll toLl(string s){ll r=0;istringstream sin(s); sin>>r; return r;}
  77. template<class T> void debug(const T& e){cout<<e<<endl;}
  78. template<class T1,class T2> void debug(const T1& e1,const T2& e2){cout<<e1<<"\t"<<e2<<endl;}
  79. template<class T1,class T2,class T3> void debug(const T1& e1,const T2& e2,const T3& e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
  80. template<class T1,class T2,class T3,class T4> void debug(const T1& e1,const T2& e2,const T3& e3,const T4& e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
  81. template<class T1,class T2,class T3,class T4,class T5> void debug(const T1& e1,const T2& e2,const T3& e3,const T4& e4,const T5& e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
  82. template<class T> void debug(vector<T>& e){int i;REP(i,SZ(e)) cout<<e[i]<<" ";cout<<endl;}
  83. template<class T> void debug(vector< basic_string<T> >& e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j];cout<<endl;} cout<<endl;}
  84. template<class T> void debug(vector< vector<T> >& e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j]<<"\t";cout<<endl;} cout<<endl;}
  85. template<class T> void debug(T e[SIZE][SIZE],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}
  86.  
  87. ll Pow(ll B,ll P){ ll R=1; while(P>0) {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
  88. //struct pq{ int cost,node;bool operator<(const pq &b)const{return cost>b.cost;}};// Min Priority Queue
  89. //bool comp(pq a,pq b){ return a.cost > b.cost;} //Comp Sort
  90.  
  91. //int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
  92. //int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
  93. //int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
  94.  
  95. vi tv,pv,expire,ans;
  96. int N,SkillBound;
  97. int dp[SIZE][SIZE][SIZE];
  98.  
  99. int rec(int tskill,int pskill,int month)
  100. {
  101. int &ret=dp[tskill][pskill][month],i;
  102.  
  103. if(ret!=-1) return ret;
  104.  
  105. if(tskill>=SkillBound && pskill >=SkillBound) return 0;
  106.  
  107. ret=INF;
  108.  
  109. REP(i,N)
  110. {
  111. if(tskill+1>=tv[i] && pskill+1>=pv[i] && month<expire[i])
  112. {
  113. ret=min(ret,rec(max(tskill,tv[i]),max(pskill,pv[i]),month+1)+1);
  114. }
  115. }
  116. return ret;
  117. }
  118. void Print(int tskill,int pskill,int month)
  119. {
  120. int ret=dp[tskill][pskill][month],i;
  121.  
  122. if(tskill>=SkillBound && pskill >=SkillBound) return ;
  123.  
  124. REP(i,N)
  125. {
  126. if(tskill+1>=tv[i] && pskill+1>=pv[i] && month<expire[i])
  127. {
  128. if(ret == rec(max(tskill,tv[i]),max(pskill,pv[i]),month+1)+1)
  129. {
  130. ans.pb(i);
  131. Print(max(tskill,tv[i]),max(pskill,pv[i]),month+1);
  132. return ;
  133. }
  134. }
  135. }
  136. }
  137. class CsCourses
  138. {
  139. public:
  140. vector <int> getOrder(vector <int> theoreticalValue, vector <int> practicalValue, vector <int> expir, int skillBound)
  141. {
  142. int res;
  143.  
  144. ans.clear();
  145. N=SZ(theoreticalValue);
  146.  
  147. tv=theoreticalValue;
  148. pv=practicalValue;
  149. expire=expir;
  150.  
  151. SkillBound=skillBound;
  152.  
  153. Clear(dp,-1);
  154. res=rec(0,0,0);
  155. if(res>=INF) return ans;
  156. Print(0,0,0);
  157. return ans;
  158. }
  159. };
  160.  
  161.  
  162. template<typename T> void print( T a ) {
  163. cerr << a;
  164. }
  165.  
  166. void print( long long a ) {
  167. cerr << a << "L";
  168. }
  169.  
  170. void print( string a ) {
  171. cerr << '"' << a << '"';
  172. }
  173.  
  174. template<typename T> void print( vector<T> a ) {
  175. cerr << "{";
  176. for ( int i = 0 ; i != a.size() ; i++ ) {
  177. if ( i != 0 ) cerr << ", ";
  178. print( a[i] );
  179. }
  180. cerr << "}" << endl;
  181. }
  182.  
  183. template<typename T> void assert_eq( int n, T have, T need ) {
  184. if ( have == need ) {
  185. cerr << "Case " << n << " passed." << endl;
  186. } else {
  187. cerr << "Case " << n << " failed: expected ";
  188. print( need );
  189. cerr << " received ";
  190. print( have );
  191. cerr << "." << endl;
  192. }
  193. }
  194.  
  195. template<typename T> void assert_eq( int n, vector<T> have, vector<T> need ) {
  196. if( have.size() != need.size() ) {
  197. cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements.";
  198. print( have );
  199. print( need );
  200. return;
  201. }
  202. for( int i= 0; i < have.size(); i++ ) {
  203. if( have[i] != need[i] ) {
  204. cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << ".";
  205. print( have );
  206. print( need );
  207. return;
  208. }
  209. }
  210. cerr << "Case " << n << " passed." << endl;
  211. }
  212. void assert_eq( int n, string have, string need ) {
  213. if ( have == need ) {
  214. cerr << "Case " << n << " passed." << endl;
  215. } else {
  216. cerr << "Case " << n << " failed: expected ";
  217. print( need );
  218. cerr << " received ";
  219. print( have );
  220. cerr << "." << endl;
  221. }
  222. }
  223.  
  224. int main( int argc, char* argv[] )
  225. {
  226.  
  227. CsCourses objectCsCourses;
  228.  
  229. //test case0
  230. vector <int> param00;
  231. param00.push_back(1);
  232. vector <int> param01;
  233. param01.push_back(1);
  234. vector <int> param02;
  235. param02.push_back(1);
  236. int param03 = 1;
  237. vector <int> ret0 = objectCsCourses.getOrder(param00,param01,param02,param03);
  238. vector <int> need0;
  239. need0.push_back(0);
  240. assert_eq(0,ret0,need0);
  241.  
  242. //test case1
  243. vector <int> param10;
  244. param10.push_back(1);
  245. param10.push_back(2);
  246. param10.push_back(1);
  247. vector <int> param11;
  248. param11.push_back(2);
  249. param11.push_back(1);
  250. param11.push_back(1);
  251. vector <int> param12;
  252. param12.push_back(5);
  253. param12.push_back(5);
  254. param12.push_back(5);
  255. int param13 = 2;
  256. vector <int> ret1 = objectCsCourses.getOrder(param10,param11,param12,param13);
  257. vector <int> need1;
  258. need1.push_back(2);
  259. need1.push_back(0);
  260. need1.push_back(1);
  261. assert_eq(1,ret1,need1);
  262.  
  263. //test case2
  264. vector <int> param20;
  265. param20.push_back(1);
  266. param20.push_back(2);
  267. param20.push_back(1);
  268. vector <int> param21;
  269. param21.push_back(2);
  270. param21.push_back(1);
  271. param21.push_back(1);
  272. vector <int> param22;
  273. param22.push_back(1);
  274. param22.push_back(1);
  275. param22.push_back(1);
  276. int param23 = 2;
  277. vector <int> ret2 = objectCsCourses.getOrder(param20,param21,param22,param23);
  278. vector <int> need2;
  279. assert_eq(2,ret2,need2);
  280.  
  281. //test case3
  282. vector <int> param30;
  283. param30.push_back(1);
  284. param30.push_back(2);
  285. param30.push_back(1);
  286. vector <int> param31;
  287. param31.push_back(2);
  288. param31.push_back(1);
  289. param31.push_back(1);
  290. vector <int> param32;
  291. param32.push_back(3);
  292. param32.push_back(2);
  293. param32.push_back(1);
  294. int param33 = 2;
  295. vector <int> ret3 = objectCsCourses.getOrder(param30,param31,param32,param33);
  296. vector <int> need3;
  297. need3.push_back(2);
  298. need3.push_back(1);
  299. need3.push_back(0);
  300. assert_eq(3,ret3,need3);
  301.  
  302. //test case4
  303. vector <int> param40;
  304. param40.push_back(1);
  305. param40.push_back(2);
  306. param40.push_back(3);
  307. param40.push_back(4);
  308. param40.push_back(5);
  309. param40.push_back(6);
  310. param40.push_back(7);
  311. vector <int> param41;
  312. param41.push_back(1);
  313. param41.push_back(2);
  314. param41.push_back(3);
  315. param41.push_back(4);
  316. param41.push_back(5);
  317. param41.push_back(6);
  318. param41.push_back(7);
  319. vector <int> param42;
  320. param42.push_back(1);
  321. param42.push_back(2);
  322. param42.push_back(3);
  323. param42.push_back(4);
  324. param42.push_back(5);
  325. param42.push_back(6);
  326. param42.push_back(7);
  327. int param43 = 7;
  328. vector <int> ret4 = objectCsCourses.getOrder(param40,param41,param42,param43);
  329. vector <int> need4;
  330. need4.push_back(0);
  331. need4.push_back(1);
  332. need4.push_back(2);
  333. need4.push_back(3);
  334. need4.push_back(4);
  335. need4.push_back(5);
  336. need4.push_back(6);
  337. assert_eq(4,ret4,need4);
  338.  
  339. //test case5
  340. vector <int> param50;
  341. param50.push_back(0);
  342. param50.push_back(1);
  343. param50.push_back(2);
  344. param50.push_back(2);
  345. param50.push_back(1);
  346. vector <int> param51;
  347. param51.push_back(0);
  348. param51.push_back(0);
  349. param51.push_back(1);
  350. param51.push_back(2);
  351. param51.push_back(1);
  352. vector <int> param52;
  353. param52.push_back(9);
  354. param52.push_back(9);
  355. param52.push_back(9);
  356. param52.push_back(9);
  357. param52.push_back(9);
  358. int param53 = 2;
  359. vector <int> ret5 = objectCsCourses.getOrder(param50,param51,param52,param53);
  360. vector <int> need5;
  361. need5.push_back(4);
  362. need5.push_back(3);
  363. assert_eq(5,ret5,need5);
  364.  
  365. }
  366.