Sunday, January 12, 2020

POJ. 3262 Protecting the Flowers

1.Problem
http://poj.org/problem?id=3262

2.Idea
Sort the cows by damage order, the process in that order all line.

3.Source
 struct Point {  
      ll t, d;  
      bool operator < (const Point &a)const {  
                return t * a.d < d * a.t;  
      }  
 } Points[100005];  
 int n;  
 int main()  
 {  
      cin >> n;  
      for (int i = 0; i < n; i++) {  
           cin >> Points[i].t >> Points[i].d;  
      }  
      sort(Points, Points + n);  
      ll ans = 0;  
      int T = 0;  
      for (int i = 0; i < n; i++) {  
           ans += T * Points[i].d;  
           T += (2 * Points[i].t);  
      }  
      cout << ans << endl;  
      return 0;  
 }  

No comments:

Post a Comment