Guest User

Power x Time

a guest
Aug 20th, 2012
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <math.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <string>
  7. #include <vector>
  8. #define ll long long int
  9. #define INF 999999999
  10.  
  11. using namespace std;
  12.  
  13. struct Program{
  14.     ll power, time;
  15.  
  16.     Program(ll _power, ll _time){
  17.         power = _power;
  18.         time = _time;
  19.     }
  20. };
  21.  
  22. ll f, p, e, a, tmpE, tmpJ;
  23.  
  24. int main(void) {
  25.     freopen("in.in", "r", stdin);
  26.     ios::sync_with_stdio(0);
  27.     while((cin >> f >> p >> e >> a) && (f + p + e + a)){
  28.         vector<Program> programs[p + 1];
  29.         for(int i = 0; i < p; i++){
  30.             for(int j = 0; j < f; j++){
  31.                 cin >> tmpE >> tmpJ;
  32.                 programs[i].push_back(Program(tmpE, tmpJ));
  33.             }
  34.         }
  35.         ll ans = 0;
  36.         int actual_freq = 1;
  37.         for(int i = 0; i < p; i++){
  38.             int miN = INF;
  39.             int idx = actual_freq;
  40.             for(int j = 0; j < f; j++){
  41.                 ll prod = programs[i][j].power * programs[i][j].time;
  42.                 if(prod < miN){
  43.                     if(j + 1 != actual_freq){
  44.                         if(prod + (e * a) < miN){
  45.                             miN = prod + (e * a);
  46.                             idx = j + 1;
  47.                         }
  48.                     }else{
  49.                         miN = prod;
  50.                         idx = j + 1;
  51.                     }
  52.                 }
  53.             }
  54.             actual_freq = idx;
  55.             ans += miN;
  56.         }
  57.         cout << ans << "\n";
  58.     }
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment