Answer the question
In order to leave comments, you need to log in
How to reduce used memory?
The program does not pass the memory limit of 1 MB.
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
int count, maximum = 0, n;
unsigned int arr_size;
cin >> arr_size;
n = arr_size;
int* arr = new int[arr_size];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 0; i < n; i++) {
count = 0;
for (int j = i + 1; j < n; j++) {
if (arr[i] == arr[j]) {
count += 1;
maximum = max(count, maximum);
}
}
}
cout << maximum+1 << endl;
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question