Zonal Computing Olympiad 2014, 30 Nov 2013

I am doing this problem. I am not able to understand the problem statement. If the given budgets are 30, 20, 53 and 14 then how maximum revenue will become 60.

You can get there by setting the price to 30, which 2 people will buy, or 20, which 3 people will buy.

1 Like

You don’t have to consider every potential customer.Just focus on max. revenue.
How?
Just sort the budgets and sell to the possible customers(whose budget is higher than the current one) and just calculate maximum value.

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
ll T;
cin>> T;
vector vec;
while(T–)
{
int a;
cin>>a;
vec.push_back(a);
}

map<int,int> mp;
for(int i = 0;i < vec.size();i++)
{
 mp[vec[i]]++;
}


int x =0;
for(auto it = mp.rbegin(); it != mp.rend(); it++) { 
	int temp = it->second; 
	mp[it->first] = x; 
	x += temp ; 
} 

vector<int> res;
int max ;

for(int i = 0;i < vec.size();i++)
{
	res.push_back((mp[vec[i]] + 1) * vec[i]  ) ; 
}

cout<<*max_element(res.begin(), res.end()); 
return 0;

}

it will give me run time error SIGTSTP in codecheff compiler when i submit my code.
but my local compiler give correct output kindly suggest me what is the problem??