# Help me in solving ZCO14003 problem

### My issue

include
using namespace std;

int main() {
int n;
cin >> n;
int customers[109] = {0};

``````for (int i = 0; i < n; i++) {
int budget;
cin >> budget;
customers[budget]++;
}

long long maxrev = 0;
for (int i = 1; i <= 108; i++) {
long long rev = 0;

for (int a = i; a <= 108; a++) {
rev += (long long)i * customers[a];
}

if (rev > maxrev) {
maxrev = rev;
}
}

cout << maxrev << endl;

return 0;
``````

}
Why am i getting run time error here?

### My code

``````#include <iostream>
using namespace std;

int main() {
int n;
cin >> n;
int customers[109] = {0};

for (int i = 0; i < n; i++) {
int budget;
cin >> budget;
customers[budget]++;
}

long long maxrev = 0;
for (int i = 1; i <= 108; i++) {
long long rev = 0;

for (int a = i; a <= 108; a++) {
rev += (long long)i * customers[a];
}

if (rev > maxrev) {
maxrev = rev;
}
}

cout << maxrev << endl;

return 0;
}

``````

Problem Link: CodeChef: Practical coding for everyone

@thenileshgarg0
Plzz refer the following code for better understanding of the logic .

``````#include <bits/stdc++.h>
using namespace std;

int main() {
long long int n;
cin>>n;
long long int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
long long int mn=0;
for(int i=0;i<n;i++)
{
mn=max(mn,a[i]*(n-i));
}
cout<<mn<<endl;
return 0;
}``````

Thank you for responding
I understood your code and gotta admit it is a better approach.
If you could tell me what went wrong with code implemented by me that would be even better.

@thenileshgarg0
Actually its not 108 it 's 10^8.
There is some problem in the formatting for this question .
That is why u are also getting run time error cozz it will get out of bound of the array.

Got it. Thanks a lot man.