Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<algorithm>
- using namespace std;
- struct worm{
- double gain;
- double cost;
- };
- bool mycmp(worm a,worm b){
- return a.cost < b.cost;
- }
- int main()
- {
- int n;
- scanf("%d",&n);
- worm arr[n+1];
- for(int i = 1 ; i <= n ; i ++){
- scanf("%lf %lf",&arr[i].gain,&arr[i].cost);
- }
- sort(arr+1,arr+1+n,mycmp);
- double rate = 0;
- double maxr = 0;
- double Ag = 0,Ac = 0;
- double sum = 0;
- for(int i = 1 ; i <= n ; i ++){
- sum += arr[i].gain;
- double rate = sum/arr[i].cost;
- if(rate > maxr){
- maxr = rate;
- Ag = sum;
- Ac = arr[i].cost;
- }
- }
- printf("%.0lf %.0lf",Ag,Ac);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement