Click Here to go back to the homepage.

Popular Vote Solution:


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

int main(){
    // #ifndef TESTING
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int nCases;
    cin >> nCases;
    while(nCases--){
        int nCandidates;
        cin >> nCandidates;
        int votes[nCandidates];
        int max = 0;
        int winnerIndex = 0;
        bool tie = false;
        for(int i = 0; i < nCandidates; i++){
            int nVotes;
            cin >> nVotes;
            votes[i] = nVotes;
            if(nVotes > max){
                winnerIndex = i + 1;
                max = nVotes;
                tie = false;
            } else if(nVotes == max){
                tie = true;
            }
        }
        if(tie){
            cout << "no winner" << endl;
            continue;
        }
        int sumLosers = 0;
        for(int i: votes){
            if(i != max){
                sumLosers += i;
            }
        }
        if(sumLosers < max){
            cout << "majority ";
        } else {
            cout << "minority ";
        }
        cout << "winner " << winnerIndex << endl;
    }
    
    return 0;   
}