-
Notifications
You must be signed in to change notification settings - Fork 0
/
notlast.cpp
47 lines (45 loc) · 1.13 KB
/
notlast.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int main() {
freopen("notlast.in", "r", stdin);
freopen("notlast.out", "w", stdout);
int N; cin >> N; map <string, int> data;
for (int i=0; i<N; i++) {
string cow; int milk;
cin >> cow >> milk;
if (data.count(cow) == 0) {
data[cow] = milk;
} else {
data[cow] += milk;
}
}
int current_lowest=100000; int current_second=100000; string output;
for (auto& cow: data) {
if (cow.second < current_lowest) {
current_lowest = cow.second;
}
}
if (data.size() != 7) {
current_lowest = 0;
}
for (auto& cow: data) {
if (cow.second < current_second && cow.second > current_lowest) {
current_second = cow.second;
output = cow.first;
}
}
int tie_counter = 0;
for (auto& cow:data) {
if (cow.second == current_second) tie_counter++;
}
if (tie_counter == 1) {
cout << output;
} else {
cout << "Tie";
}
}