/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 496.0 KiB
#2 Wrong Answer 3ms 332.0 KiB
#3 Wrong Answer 27ms 568.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int T;
    cin >> T;
    
    while(T--){
        long long N, M;
        cin >> N >> M;
        long long total = N * M;
        vector<long long> A(total);
        for(auto &x: A) cin >> x;
        
        // Sort all elements in ascending order
        sort(A.begin(), A.end());
        
        // Determine the sizes of Set A and Set B
        long long A_size = (total + 1) / 2; // ceil(N*M / 2)
        long long B_size = total / 2;       // floor(N*M / 2)
        
        // Assign the largest A_size elements to Set A
        // and the next largest B_size elements to Set B
        // Since A is sorted in ascending order:
        // Set A: last A_size elements
        // Set B: next B_size elements
        long long min_A = A[total - A_size];
        long long min_B;
        if(B_size > 0){
            min_B = A[total - A_size - B_size];
        }
        else{
            // If B_size is 0, there are no elements in Set B
            // Depending on problem constraints, set B_sum appropriately
            // Here, assuming B_sum is 0 if Set B is empty
            min_B = 0;
        }
        
        // Calculate the minimal sum S
        long long S = min_A + min_B;
        
        // Output the result
        cout << S << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1065 Matrix Sum
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-05 03:11:45
Judged At
2024-11-11 02:40:53
Judged By
Score
5
Total Time
27ms
Peak Memory
568.0 KiB