Frustrated coders problem

closed account (1vf9z8AR)
There are N frustrated coders standing in a circle with a gun in their hands. Each coder has a skill value S[ i ] and he can only kill those coders that have strictly less skill than him. One more thing, all the guns have only 1 bullet. This roulette can take place in any random order. Fortunately, you have the time stone and you can see all possible outcomes of this scenario. Find the outcome where the total sum of the remaining coder's skill is minimum. Print this sum.

INPUT

The first line contains N the no. of coders

The next line contains N elements where the ith element is theS[ i ] of ith coder.

OUTPUT

Print a single line containing the minimum sum

CONSTRAINTS

1<= N <= 1000000

1<=S[ i ]<=1000

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>arr;
    int temp;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        arr.push_back(temp);
    }
    sort(arr.begin(),arr.end());
    int top=0;
    for(int i=1;i<n;i++)
    {
        if(arr[i]!=arr[top])
        {
            top++;
        }
    }
    int sum=0;
    for(int i=top;i<n;i++)
        sum+=arr[i];
    cout<<sum;
    return 0;
}


I am getting the wrong answer for big inputs. Possible because no of inputs can be 10^6. Any workaround?
Last edited on
unsigned long long instead of int?
Describe your algorithm. Your variables names are not descriptive.
Topic archived. No new replies allowed.