Submission #82681

# Submission time Handle Problem Language Result Execution time Memory
82681 2018-11-01T10:20:00 Z heon Pareto (COCI17_pareto) C++11
30 / 80
78 ms 1872 KB
#include<bits/stdc++.h>

using namespace std;

int main(){
	
	int n;
	scanf("%d", &n);
	vector <int> v(n);
	int sum = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &v[i]);
		sum += v[i];
	}
	sort(v.rbegin(), v.rend());
	int curr = 0;
	double a, b;
	double mx = -1.0, solb, sola;
	for(int i = 0; i < n; i++){
		curr += v[i];
		a = (double) (i+1) / n;
		b = (double) curr / sum;
		if(b - a > mx){
			solb = b, sola = a;
			mx = b - a;
		}
	}
	cout << fixed << setprecision(15) << sola * 100 << "\n";
	cout << fixed << setprecision(15) << solb * 100;
}

Compilation message

pareto.cpp: In function 'int main()':
pareto.cpp:8:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
pareto.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v[i]);
   ~~~~~^~~~~~~~~~~~~
pareto.cpp:28:46: warning: 'sola' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << fixed << setprecision(15) << sola * 100 << "\n";
                                              ^~~
pareto.cpp:29:46: warning: 'solb' may be used uninitialized in this function [-Wmaybe-uninitialized]
  cout << fixed << setprecision(15) << solb * 100;
                                              ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 500 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Incorrect 2 ms 500 KB Output isn't correct
5 Incorrect 6 ms 500 KB Output isn't correct
6 Incorrect 31 ms 900 KB Output isn't correct
7 Incorrect 61 ms 1288 KB Output isn't correct
8 Incorrect 78 ms 1872 KB Output isn't correct