Why is my code not getting accepted even when i have tested all selfmade testcases to be running correctly My code is at given link link asked 08 Nov '15, 11:57

Here's my solution to the problem. Also could you please upvote my answer as I need karma points to ask a question related to the olympiad, I'm having problems with little red riding hood
answered 11 Nov '15, 12:23

import java.util.*; class Smartphone { public static void main(String args[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter the data in the given format"); int N=sc.nextInt(); //Stores number of potential customers int budg[]=new int[N]; //Array to store budget of customers for(int i=0;i<N;i++) budg[i]=sc.nextInt();
} answered 29 Sep '16, 13:22
But your sorting method is not efficient,you can use Arrays.sort(which uses quick sort(more efficient then this). Thanks upvote if you like my amswer,and accept my gift(10 points)
(29 Sep '16, 17:57)

You are overcomplicating the things. Do this : Sort the array. let the 0indexed array be arr[i] You know that for each element , the elements after it will have the budget >= arr[i] . So, traverse backwards. For each i, if we choose arr[i] as the price for app, we will get arr[i]*(ni) rupees (Becase all the people after the current person will at least arr[i] money so they will buy this.) Here's the code if you have any doubts but seriously first understand and try it yourself : https://www.codechef.com/viewsolution/8716059
answered 08 Nov '15, 12:37

+theweblover007 Why doesn't my code work for the second test case,because I think my solution is similar to yours. answered 08 Nov '15, 22:56

nvm got it,thanks for your answer though I was trying to sort using merge sort like the OP but the built in sort function is way easier and I guess quicker. answered 08 Nov '15, 23:11

Lines 2433 is where the problem is. In this problem, if we sort the array in increasing order, then the revenue generated for a given price in the array will be generated by all customers after that in the array as they will have higher prices to offer. As reference, you might want to look at this short and simple code.
answered 09 Nov '15, 10:09

Hi everyone. Can past year ZCO participants explain how is the whole procedure of submitting the answers in the competition. Suppose if I submit a wrong answer, will I get another chance? As for the post above, my solution was this https://www.codechef.com/viewsolution/8714051 or answered 10 Nov '15, 12:49

You can check out here if you have any doubt the post link ishttp://ideone.com/jgUGPL answered 10 Nov '15, 13:18

First I also made a O(n^2) solution but that will obviously not pass the second subtask. What you need to do is simply sort the array in descending order and start from the biggest element. Keep going to the smaller element and in the loop find out the product of a[i]*(ni). The biggest element after processing this is your answer. Apart from the sorting this is o(n) and with O(n log n) so a pretty good improvement I would say. I got 100. include<bits stdc++.h="">using namespace std; define ll long longdefine e '\n'int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ll n; cin>>n; int a[n]; for(int i=0;i<n;i++) cin="">>a[i]; sort(a,a+n); ll ma=0,tmp=0; for(int i=n1;i>=0;i){ tmp=a[i]*(ni); ma=max(tmp,ma); } cout<<ma; return 0; } answered 11 Nov '15, 11:41

What's wrong with my code (excluding the slow sorting algorithm)? https://ideone.com/pKbqZh answered 15 Nov '15, 22:15

@owneriekno1 , Why the hell are you not sorting using inbuilt sort function, its way easier and way faster. just write : sort(arr,arr+n); Also, add : #include<bits stdc++.h=""> and remove every other includes file. Makes the coding easier. Also, a hint : Look for corner cases. answered 16 Nov '15, 12:57

Try this.. It's simple .....It's Working
answered 17 May '18, 19:24
