P4086 [USACO17DEC]My Cow Ate My Homework

Title Description

In your bovine history class, you have been given a rather long homework assignment with NNquestions (3 \leq N \leq 100,0003N100,000), each graded with an integer score in the range 0...10,000. As is often customary, your teacher plans to assign a final grade by discarding a question on which you received the lowest score and then averaging the remaining scores together. Unfortunately, your pet cow Bessie has just eaten your answers to the first KK questions! (KK could be as small as 1 or as large as N-2N2).

After copious explanation, your teacher finally believes your story, and agrees to grade the remaining non-eaten part of the assignment the same way as before -- by removing the lowest-scoring question (or one such question, in the event of a tie) and averaging the rest.

Please output all values of KK which would have earned you the maximum possible score according to this grading scheme, in sorted order.

In your history class, you get a very long job. This job contains a title of N (3 ≤ N ≤ 100,000), each topic scores between 0 and 10,000.

By convention, your teacher final score is calculated as follows: remove the lowest you a score, and then score the rest of the grade point average as the final score. Unfortunately, your pet cow "Bessie" just ate answer the first K topic! (1 ≤ K ≤ N-2)

After you some explanation, the teacher finally believe your story, and agreed to have the answer to your topic (not subject eaten answers) as before to divide - by removing the lowest score (if there are multiple lowest results, only one of which is removed) and averaging the remaining scores score.

According to the results of this calculation scheme, output in ascending order all the values ​​that you can make the most of the final results of K.

Input Format

The first line of input contains NN, and the next line contains the scores on the NN homework questions.

Output Format

Please output, one value per line, all values of KK which would have earned you the maximum possible score.

Sample input and output

Input # 1
5
3 1 9 2 7
Output # 1
2

Description / Tips

If Bessie eats the first two questions, then the remaining scores are 9, 2, and 7. Removing the minimum and averaging, we get a final grade of 8, which is the highest possible.

 

 

#include<bits/stdc++.h>
using namespace std;
const int N=100005;

int n;
int a[N];
int mn[N];
int pre[N];
double ans[N];

int gi(){
  int ans=0,f=1;char i=getchar();
  while(i<'0'||i>'9'){if(i=='-')f=-1;i=getchar();}
  while(i>='0'&&i<='9'){ans=ans*10+i-'0';i=getchar();}
  return ans*f;
}

int main(){
  n=gi(); double ave = 0 , mx;
  memset(mn,127,sizeof(mn));
  for(int i=1;i<=n;i++) a[i]=gi(),pre[i]=pre[i-1]+a[i];
  for(int i=n;i>=1;i--) mn[i]=min(mn[i+1],a[i]);
  for(int i=1;i<n;i++){
    if(ave<=(pre[n]-pre[i]-mn[i+1])*1.0/(n-i-1)){
      ave=(pre[n]-pre[i]-mn[i+1])*1.0/(n-i-1);
      mx=ave; ans[i]=ave;
    }
  }
  for(int i=1;i<=n;i++)
    if(ans[i]==mx) printf("%d\n",i);
  return 0;
}

 

Guess you like

Origin www.cnblogs.com/hrj1/p/11774711.html