Not sure what's going at all, title says it all. When I mean inputting the test cases individually, I mean writing to the console each test case with the keyboard, not just pasting them into the console. The problem I'm trying to solve is https://codeforces.com/problemset/problem/1335/C. I'm not sure how to really debug the issue either because when I tried using the debugger for the first test case:
4
7
4 2 4 1 4 3 4
5
2 1 5 4 3
1
1
4
1 1 1 3
The debugger would stop before finishing the last test case as well.
2
11
11 2 10 8 6 2 8 5 10 5 9
12
6 7 4 6 2 2 10 9 12 1 8 3
My program also doesn't work for the above test case if you copy and paste it into the console all at once, but if you manually input each test case it works.
My code:
#include <iostream>
#include <set>
int main() {
int t, n, a;
std::cin >> t;
for (int i = 0; i < t; i++) {
std::cin >> n;
std::multiset<int> students;
for (int j = 0; j < n; j++) {
std::cin >> a;
students.insert(a);
}
if (students.size() == 1 || students.size() == 0) {
std::cout << 0 << std::endl;
} else {
std::pair<int, int> greatest = std::make_pair(*students.begin(), students.count(*students.begin()));
for (auto k = ++students.begin(); k != students.end(); ++k) {
if (*k != greatest.first && students.count(*k) > greatest.second) {
greatest = std::make_pair(*k, students.count(*k));
}
}
std::multiset<int> tempStudents;
for (int k = 0; k < greatest.second; ++k) {
tempStudents.insert(greatest.first);
}
for (auto k : students) {
if (k != greatest.first && tempStudents.count(k) == 0) {
tempStudents.insert(k);
}
}
students = tempStudents;
int duplicate = greatest.second, unique = students.size() - duplicate;
if (unique == duplicate) {
std::cout << unique << std::endl;
} else if (duplicate > unique) {
int compare = (unique + 1) * 2;
if (students.size() > compare) {
std::cout << students.size() - compare << std::endl;
} else if (students.size() == compare) {
std::cout << unique + 1 << std::endl;
} else { //duplicate = unique + 1
std::cout << unique << std::endl;
}
} else {
std::cout << duplicate << std::endl;
}
}
}
}
Any thoughts?