Smart Phone

This is my code which fails a few test cases, what am I doing wrong? Please help me with this
#include
#include
#include
using namespace std;
int main() {
int N;
vectornum;
long long int sum = 0;
cin >> N;
for (int i = 0; i < N; i++) {
long long int x;
cin >> x;
num.push_back(x);
}
sort(num.begin(), num.end());
for (auto i = num.begin(); i != num.end(); i++) {
sum = sum + (*i);
}
sum = sum / N;

    	long long int count=0;

    	for (auto i = num.begin(); i != num.end(); i++) {
    		if (*i >= sum) {
    			count++;
    		}
    	}
    	auto it = lower_bound(num.begin(), num.end(), sum);
    	cout << count * (*it);
    	return 0;
    }

Why the hell are you spamming forum by creating multiple crappy posts from your fake account, format your code properly, and explain what have you done otherwise don’t expect any sort of help from here. ATLEAST BOTHER TO GIVE PROBLEM LINK

2 Likes

My apologies. I am still new to this. I don’t know why it was posted multiple times.
#include
#include
#include
using namespace std;
int main() {
long long int N;
vectornum;
long long int sum = 0;
cin >> N;
for (int i = 0; i < N; i++) {
long long int x;
cin >> x;
num.push_back(x); //input
}
sort(num.begin(), num.end()); //sorted the vector
for (auto i = num.begin(); i != num.end(); i++) {
sum = sum + (*i);
}
sum = sum / N; //mean of all the values

long long int count=0;

for (auto i = num.begin(); i != num.end(); i++) {
	if (*i >= sum) {
		count++; //number of values satisfying the mean
	}
}
auto it = lower_bound(num.begin(), num.end(), sum); //first number closest to mean
cout << count * (*it); //final revenue
return 0;

}
And this is the problem link: https://www.codechef.com/LRNDSA01

Check this

1 Like

Thank you. I got it, I was approaching it differently.

1 Like