Codeforces 801C Voltage Keepsake Structure sort order + greedy

Source: Internet
Author: User
Tags pow

#include <bits/stdc++.h>using namespacestd;structin{Long LongA, B; DoubleT;} s[100005];BOOLCMP (in P, in Q) {if(P.T <q.t)return true; Else if(p.t = = q.t && P.a <q.a)return true; return false;}intMain () {Long LongN, p; scanf ("%lld%lld", &n, &p); Long LongSUM1 =0;  for(Long Longi =0; I < n; i++) {scanf ("%lld%lld", &AMP;S[I].A, &s[i].b); Sum1+=s[i].a; S[I].T= s[i].b *1.0/s[i].a; }    if(Sum1 <=p) {printf ("-1\n"); }    Else{sort (s, S+N, CMP); //for (int i = 0; i < n; i++)//printf ("%lld--a%lld--b%.9f--t\n\n", S[i].a, s[i].b, s[i].t);        DoubleTime = s[0].t; DoublePOW = s[0].T *p; DoubleDis, x; Long Longsum = s[0].a; Long Longi =1;  while(I <n) {dis= s[i].t-Time ; if(Sum >p) {x= POW/(Sum-p); if(x <=dis) {printf ("%.10f\n", Time +x);  Break; }} POW= Pow + dis * (P-sum); Sum+=s[i].a; time=s[i].t; I++; }        if(i = =N) {x= POW/(Sum-p); printf ("%.10f\n", Time +x); }    }    return 0;}

Codeforces 801C Voltage Keepsake Structure sort order + greedy

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.