fork download
  1. /*
  2.   * GSJANB
  3.   * Author: Omkar Prabhu <omkar.prabhu15@siesgst.ac.in>
  4.   */
  5. #include <bits/stdc++.h>
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(0);
  12. // Start Solution here
  13. int t;
  14. cin >> t;
  15. while (t--) {
  16. int n;
  17. cin >> n;
  18. long long a[n][n];
  19. for (int i = 0; i < n; i++) {
  20. for (int j = 0; j < n; j++) cin >> a[i][j];
  21. sort(a[i], a[i]+n);
  22. }
  23. long long ans = 0;
  24. for (int i = 0; i < n; i++) {
  25. ans += (long long)abs(a[i][n-1] - a[i][0]);
  26. }
  27. cout << ans << endl;
  28. }
  29. // End Solution here
  30. return 0;
  31. }
Time limit exceeded #stdin #stdout 5s 2354740KB
stdin
Standard input is empty
stdout
Standard output is empty