/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Wrong Answer 17ms 540.0 KiB
#3 Wrong Answer 26ms 580.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
int32_t main() {
     ios_base::sync_with_stdio(false);
     cin.tie(0); cout.tie(0);
     int t; cin >> t;
     while (t--) {
        int n, k; cin >> n >> k;
        vector <int> a(n);
         for (int i = 0; i < n; i++) cin >> a[i];

        vector <int> v1;
        vector <int> v2;

        for (int i = 0; i < k; i++) v1.push_back(a[i]);
        for (int i = 0; i < k; i++) v2.push_back(0);
        for (int i = k; i < n; i++) v2.push_back(a[i]);

        int mx = -1e5 + 7;
        int mx_idx = 0;
        int mn = 1e5 + 7;
        int mn_idx = 0;
        for (int i = 0; i < k; i++) {
            if (v1[i] > mx) {
                mx = v1[i];
                mx_idx = i;
        }
        }
        for (int i = k; i < n; i++) {
            if (v2[i] < mn){
                mn = v2[i];
                mn_idx = i;
            } 

        }
        
        if(mn < mx) {
            swap (a[mx_idx], a[mn_idx]);
        }
       long long sum = 0;
       
       for (int i = 0; i < k; i++) sum += a[i];
          cout << sum << '\n';
     }
}

Information

Submit By
Type
Submission
Problem
P1149 Swap and Minimize
Contest
LU IUJPC : Sylhet Division 2024
Language
C++17 (G++ 13.2.0)
Submit At
2024-12-09 07:06:26
Judged At
2024-12-09 07:06:26
Judged By
Score
1
Total Time
26ms
Peak Memory
580.0 KiB