Sunday, January 12, 2020

POJ.2393 Yogurt factory

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

2. Idea
Each week, comparing current week cost and last week cost + storage cost, choose the small one.

3. Source
 int n;  
 ll s;  
 ll total = 0;  
 ll cur = 0;  
 int main()  
 {  
      cin >> n >> s;  
      for (int i = 0; i < n; i++) {  
           ll c, y;  
           cin >> c >> y;  
           if (i == 0) {  
                cur = c;  
                total = cur * y;  
                continue;  
           }  
           cur = min(cur + s, c);  
           total += (cur * y);  
      }  
      cout << total << endl;  
      return 0;  
 }  

No comments:

Post a Comment