[CF1829C] Mr. Perfectly Fine 题解
qifan_maker · · 题解
题目链接
洛谷
Codeforces
题意分析
PF 先生想要学习两个技能,他一共有 -1。
题目解法
用
如果技能 1 或技能 2 没有被学会,并且没有能同时学会两个技能的书,就输出 -1;否则输出
UPD on 2023.5.7
被 hack 了,发现是
1
2
200000 01
200000 10
原帖存档
AC Code
/*
Problem:
C. Mr. Perfectly Fine
By:
qifan_maker
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _5e5 114514*5
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--){
int n;
cin >> n;
int x=_5e5,y=_5e5,z=_5e5,ans=0;
while (n--){
int a;
string b;
cin >> a >> b;
if (b == "11"){
z = min(z,a);
}
else if (b[0] == '1'){
x = min(x,a);
}
else if (b[1] == '1'){
y = min(y,a);
}
}
if ((x==_5e5 or y==_5e5) and z==_5e5){
cout << -1 << endl;
}
else {
cout << min(x+y,z) << endl;
}
}
return 0;
}