-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1730A.cpp
More file actions
35 lines (31 loc) · 972 Bytes
/
Copy path1730A.cpp
File metadata and controls
35 lines (31 loc) · 972 Bytes
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
// Created on 18-Feb-24
//done ac
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, c;
cin >> n >> c;
int arr[n];
int counter[101] = {0}; //n+1 cause n
for (int i = 0; i < n; i++) {
cin >> arr[i];
counter[arr[i]]++;
}
sort(arr, arr + n); //sorted only so that the next loop doesnt run n times in best case scenario.
int PUcounter = 0;
for (int i = 1; i <= arr[n - 1]; i++) { //arr[n-1] is the largest number in sorted array
if (counter[i] == 1) {
PUcounter++;
} else if (counter[i] > 1 && counter[i] >= c) // note ,for counter[i]=0, condition is not needed.
PUcounter += c;
else if (counter[i] > 1 && counter[i] < c)
PUcounter += counter[i];
}
cout << PUcounter << endl;
}
return 0;
}