1 solutions

  • 0
    @ 2025-12-10 21:35:24
    #include<bits/stdc++.h>
    using namespace std;
    #define int long long
    int n;
    int sz[100006][3];
    
    signed main() {
    	int zsss;
    	cin >> zsss;
    	while (zsss--) {
    vector<pair<int, int>>ve[4];
         
    		cin >> n;
    		int total = 0;
    		for (int i = 1; i <= n; i++) {
    
    			cin >> sz[i][1] >> sz[i][2] >> sz[i][3];
    			if (sz[i][1] >= sz[i][2] && sz[i][1] >= sz[i][3]) {
    				total += sz[i][1];
    				ve[1].push_back({i, sz[i][1]});
    			} else if (sz[i][2] >= sz[i][1] && sz[i][2] >= sz[i][3]) {
    				ve[2].push_back({i, sz[i][2]});
    				total += sz[i][2];
    			} else if (sz[i][3] >= sz[i][1] && sz[i][3] >= sz[i][2]) {
    				ve[3].push_back({i, sz[i][3]});
    				                total += sz[i][3];
    			}
    
    		}
    //cout<<total<<endl;
    		if (ve[1].size() > n / 2) {
    		//	cout<<111<<endl;
    			priority_queue<int, vector<int>, greater<>>q;
    			for (auto t : ve[1]) {
    				q.push(min(t.second-sz[t.first][2] , t.second-sz[t.first][3] ));
    
    			}
    			for (int i = 1; i <= ve[1].size() - n / 2; i++) {
    			
    				total -= q.top();
    				q.pop();
    			}
    
    		} else if (ve[2].size() > n / 2) {
    			//	cout<<222<<endl;
    			priority_queue<int, vector<int>, greater<>>q;
    			for (auto t : ve[2]) {
    				q.push(min(t.second-sz[t.first][1] ,t.second- sz[t.first][3]));
    			//	cout<<min(sz[t.second-t.first][1] ,t.second- sz[t.first][3])<<endl;
    
    			}
    			for (int i = 1; i <= ve[2].size() - n / 2; i++) {
    			//	cout<<q.top()<<endl;
    				total -= q.top();
    				q.pop();
    			}
    
    		} else if (ve[3].size() > n / 2) {
    			//	cout<<333<<endl;
    			priority_queue<int, vector<int>, greater<>>q;
    			for (auto t : ve[3]) {
    				q.push(min(t.second-sz[t.first][1] , t.second-sz[t.first][2]));
    
    			}
    			for (int i = 1; i <= ve[3].size() - n / 2; i++) {
    				total -= q.top();
    				q.pop();
    			}
    
    		}
    
    		cout << total<<endl;
    	}
    }
    
    
    
    
    
    
    
    
    • 1

    Information

    ID
    504
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    10
    Tags
    (None)
    # Submissions
    2
    Accepted
    2
    Uploaded By