#include #include #include #include using namespace std; const int N = 5000; int jars[N]; int n; void init() { FILE *pFile; pFile = fopen("pooh.in","r"); fscanf(pFile,"%d",&n); for (int i = 0; i < n; i++) { fscanf(pFile,"%d",&jars[i]); } fclose(pFile); } int findBest() { if (n == 1) return jars[0]; int maxSum = 0; int maxJar = jars[0]; int tempSum = jars[n-1]; for (int i = n-2; i>= 0; i--) { if (jars[i] == jars[i+1]) { tempSum+=jars[i]; } else { if (maxSum < tempSum) { maxSum = tempSum; maxJar = jars[i+1]; tempSum = jars[i]; } } } if (maxSum < tempSum) { maxSum = tempSum; maxJar = jars[0]; } return maxJar; } int main() { FILE * pFile; pFile = fopen("pooh.out","w"); init(); sort(jars,jars+n-1); fprintf(pFile,"%d",findBest()); fclose(pFile); return 0; }