[原帖存档][CF1829C] Mr. Perfectly Fine 题解
qifan_maker · · 个人记录
题目链接
洛谷
Codeforces
题意分析
PF 先生想要学习两个技能,他一共有 -1。
题目解法
用
如果技能 1 或技能 2 没有被学会,并且没有能同时学会两个技能的书,就输出 -1;否则输出
AC Code
/*
Problem:
C. Mr. Perfectly Fine
By:
qifan_maker
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _2e5 114514*2
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=_2e5,y=_2e5,z=_2e5,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==_2e5 or y==_2e5) and z==_2e5){
cout << -1 << endl;
}
else {
cout << min(x+y,z) << endl;
}
}
return 0;
}