kar7mp5
[Codeforces] Codeforces Round 950 (Div. 3) A, B 풀이 본문
Problem Solving/Codeforces
[Codeforces] Codeforces Round 950 (Div. 3) A, B 풀이
kar7mp5 2024. 6. 4. 15:52728x90
문제 링크:
https://codeforces.com/contest/1980
Dashboard - Codeforces Round 950 (Div. 3) - Codeforces
codeforces.com
해결한 문제가 2개라 앞으로는 늘려가는 방향으로 노력해야 겠습니다.
A
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T, N, M;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> T;
while (T--) {
cin >> N >> M;
string problems;
cin >> problems;
vector<int> cnt(7, 0);
for (char c : problems) {
if (c == 'A') cnt[0]++;
else if (c == 'B') cnt[1]++;
else if (c == 'C') cnt[2]++;
else if (c == 'D') cnt[3]++;
else if (c == 'E') cnt[4]++;
else if (c == 'F') cnt[5]++;
else if (c == 'G') cnt[6]++;
}
int result = 0;
result += max(0, M - cnt[0]);
result += max(0, M - cnt[1]);
result += max(0, M - cnt[2]);
result += max(0, M - cnt[3]);
result += max(0, M - cnt[4]);
result += max(0, M - cnt[5]);
result += max(0, M - cnt[6]);
cout << result << endl;
}
return 0;
}
B
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T;
int N, F, K;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> T;
while (T--) {
cin >> N >> F >> K;
vector<int> v;
int tmp;
for (int i = 0; i < N; ++i) {
cin >> tmp;
v.push_back(tmp);
}
int dmitry = v[F-1];
int cnt = 0;
for (int i = 0; i < N; ++i)
if (v[i] == dmitry)
++cnt;
sort(v.begin(), v.end());
for (int i = 0; i < K; ++i) {
v.pop_back();
}
int cnt2 = 0;
for (int i = 0; i < N-K; ++i) {
if (v[i] == dmitry) {
++cnt2;
}
}
if (cnt2 != 0) {
if (cnt == cnt2) {
cout << "NO" << '\n';
}
else {
cout << "MAYBE" << '\n';
}
}
else {
cout << "YES" << '\n';
}
}
return 0;
}
728x90
'Problem Solving > Codeforces' 카테고리의 다른 글
[Codeforces] Codeforces Round 951 (Div. 4) A, B, C, E 풀이 (0) | 2024.06.21 |
---|---|
[Codeforces] Codeforces Round 951 (Div. 2) A, C 풀이 (0) | 2024.06.07 |