fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. void sol(){
  5. int n, k;
  6. cin >> n >> k;
  7. int a[n], ans = 0;
  8. for(int &i:a) cin >> i;
  9. for(int i = 0; i < n / 2; i++) ans += min(k, abs(a[i] - a[n - i - 1]));
  10. cout << ans << "\n";
  11.  
  12. }
  13. signed main(){
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL);
  16. cout.tie(NULL);
  17. int t = 1;
  18. cin >> t;
  19. while(t--){
  20. sol();
  21. }
  22. return 0;
  23. }
Runtime error #stdin #stdout 0.02s 5280KB
stdin
Standard input is empty
stdout
Standard output is empty