Help on why this code is wrong (NUMBERS)?!

Problem: NUMBERS (It seemed rather easy at first!)

My solution:

#include <bits/stdc++.h>

using namespace std;

typedef long long lld;

bool comp(pair<string, lld> p1, pair<string, lld> p2) {
    return p1.second < p2.second;

int main() {
    lld T;
    cin >> T;
    while (T--) {
        lld N;
        cin >> N;
        vector<pair<string, lld>> name;
        while (N--) {
            string str;
            lld Ai;
            cin >> str >> Ai;
            name.emplace_back(str, Ai);
        sort(name.begin(), name.end(), comp);
        bool flag = false;
        for (lld i = 1; i < name.size() - 1; i++)
            if (name[i].second != name[i + 1].second && name[i].second != name[i - 1].second) {
                cout << name[i].first << '\n';
                flag = true;
        if (!flag)
            cout << "Nobody wins.\n";
    return 0;

My approach:
The approach is simple! I push the names and the called numbers into a vector. I sort it in increasing order. I traverse it again while checking if the numeric element of that index is not equal to the next or the previous one. If so, I output the element.

1 Like

Did you allow the highest number given to win, when all lower values are duplicated?

Kouta 1
Yuka 1
Mayu 3
Lucy 3
Nana 5

should give

1 Like

How about now?

Did the required changes! Still not working!

Please help.

And the lowest number if unique…

Kouta 1
Yuka 2
Mayu 3
1 Like