fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7. while (t--) {
  8. int n, k;
  9. cin >> n >> k;
  10. vector<long long> a(n);
  11. for (long long &x : a) cin >> x;
  12.  
  13. long long ans = 0;
  14. for (int i = 0; i < k - 1; i++) {
  15. long long mx = i <= n - k ? max(a[i], a[n - i - 1]) : 0;
  16. a[i] = a[n - i - 1] = 0;
  17. ans += mx;
  18. }
  19. ans += accumulate(a.begin(), a.end(), 0LL);
  20. cout << ans << '\n';
  21. }
  22. }
  23.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
Standard output is empty