-
Notifications
You must be signed in to change notification settings - Fork 0
/
mrPerfectlyFine.cpp
83 lines (70 loc) · 1.13 KB
/
mrPerfectlyFine.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// codeforces, Mr. Perfectly fine
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll binToInt(string s)
{
if (s[0] == '1')
{
if (s[1] == '1')
return 3;
else
return 2;
}
else
{
if (s[1] == '1')
return 1;
else
return 0;
}
}
void solve()
{
ll books;
ll tm_1 = INT_MAX;
ll tm_2 = INT_MAX;
ll tm_3 = INT_MAX;
bool f1 = false;
bool f2 = false;
bool f3 = false;
cin >> books;
for (ll i = 0; i < books; i++)
{
ll tm;
ll skl;
string s;
cin >> tm;
cin >> s;
skl = binToInt(s);
if (skl == 1){
tm_1 = min(tm, tm_1);
f1 = true;
}
else if (skl == 2){
tm_2 = min(tm, tm_2);
f2 = true;
}
else if (skl == 3){
tm_3 = min(tm, tm_3);
f3 = true;
}
}
if ((!f1 || !f2)&&!f3)
{
cout << -1 << "\n";
return;
}
cout << min((tm_1 + tm_2), tm_3) << "\n";
return;
}
signed main()
{
// solve();
// return 0;
ll testCases;
cin >> testCases;
while (testCases--)
solve();
return 0;
}