fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int n, nTest;
  8. int a[111], ret[111];
  9. pair<int, int> b[111];
  10.  
  11. int main() {
  12. freopen("cubes.in", "r", stdin);
  13. // freopen("cubes.out", "w", stdout);
  14. scanf("%d", &nTest);
  15. for(int test = 1; test <= nTest; test++) {
  16. scanf("%d", &n);
  17. for(int i = 1; i <= n; i++) {
  18. scanf("%d", a+i);
  19. b[i] = make_pair(i*(n-i+1), -i);
  20. }
  21. sort(a+1, a+1+n, greater<int>());
  22. sort(b+1, b+1+n);
  23. for(int i = 1; i <= n; i++)
  24. ret[-b[i].second] = a[i];
  25. printf("Case %d:\n", test);
  26. for(int i = 1; i <= n; i++) printf("%d ", ret[i]);
  27. if (test < nTest) printf("\n");
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 2684KB
stdin
Standard input is empty
stdout
Standard output is empty