Advertisement
Riz1Ahmed

B. CGPA (LU Intra 2020)

Feb 9th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. /********************
  2. Riz1 Ahmed, CSE, LU.
  3. fb.com/riz1ahmed
  4. Code Start Time: 2020-02-09-17.20
  5. ********************/
  6. #include<bits/stdc++.h>
  7. #define Fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
  8. #define FOR(i,l,r) for(i=l;i<=r;i++)
  9. #define ll long long int
  10. void Print(ll n) {printf("%lld\n",n);}
  11. const ll Mod=1e9+7,MX=1e7;
  12. using namespace std;
  13. struct R{ double cr,gpa;};
  14.  
  15. double totcr,totgpa;
  16.  
  17. bool cmp(R a,R b){
  18.     double acgpa=(totgpa-a.gpa+4)/(totcr);
  19.     double bcgpa=(totgpa-b.gpa+4)/(totcr);
  20.  
  21.     return (acgpa<bcgpa);
  22. }
  23. int main(){
  24.     string s;
  25.     double n,ex,i,cr,gpa;
  26.     while(cin>>n>>ex){
  27.         vector<R> v;
  28.         totcr=0,totgpa=0;
  29.         for (i=0; i<n; i++){
  30.             cin>>s>>cr>>gpa;
  31.             if (!gpa) continue;
  32.             //printf("%.1f,%1f\n",cr,gpa);
  33.             if (gpa<=2.75) v.push_back({cr,gpa});
  34.             totgpa+=cr*gpa;
  35.             totcr+=cr;
  36.             //printf("Total Creadit=%.1f, Total CGPA=%.1f\n",totcr,totgpa);
  37.         }
  38.         double cgpa=totgpa/totcr;
  39.         int c=0;
  40.         //printf("CGPA=%.1f\n\n",cgpa);
  41.         sort(v.begin(), v.end(),cmp);
  42.         //for (auto it:v) printf("%.1f %.1f\n",v[i].cr,v[i]);
  43.         //printf("%.0lf\n",c);
  44.         while (v.size() && cgpa<ex){
  45.             c++;
  46.             cr=v.back().cr, gpa=v.back().gpa, v.pop_back();
  47.             totgpa-=cr*gpa, totgpa+=cr*4.0;
  48.             cgpa=totgpa/totcr;
  49.         }
  50.         if(cgpa<ex) puts("Impossible");
  51.         else printf("%d\n",c);
  52.     }
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement