fork download
  1. vector <int> getOrdering( vector <int> height, vector <int> bloom, vector <int> wilt )
  2. {
  3. int n = height.size();
  4. vector < vector <int> > mat (n, vector <int> (n, 0));
  5. vector <int> deg (n, 0);
  6. vector <int> mark (n, 0);
  7. for (int i = 0; i < n; i++)
  8. for (int j = 0; j < n; j++)
  9. if ( height[i] < height[j] &&
  10. ( (bloom[i] >= bloom[j] && bloom[i] <= wilt[j]) || (bloom[j] >= bloom[i] && bloom[j] <= wilt[i]) )
  11. )
  12. {
  13. mat[i][j] = 1;
  14. deg[j]++;
  15. }
  16. vector <int> res;
  17. for (int i = 0; i < n; i++)
  18. {
  19. int maxi = -1;
  20. int ind = -1;
  21. for (int j = 0; j < n; j++)
  22. if (!deg[j] && !mark[j] && height[j] > maxi)
  23. {
  24. maxi = height[j];
  25. ind = j;
  26. }
  27. mark[ind] = 1;
  28. res.push_back (maxi);
  29. for (int j = 0; j < n; j++)
  30. if (mat[ind][j])
  31. deg[j]--;
  32. }
  33. return res;
  34. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty