Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <math.h>
- #include <stdio.h>
- #include <string.h>
- #include <string>
- #include <vector>
- #define ll long long int
- #define INF 999999999
- using namespace std;
- struct Program{
- ll power, time;
- Program(ll _power, ll _time){
- power = _power;
- time = _time;
- }
- };
- ll f, p, e, a, tmpE, tmpJ;
- int main(void) {
- freopen("in.in", "r", stdin);
- ios::sync_with_stdio(0);
- while((cin >> f >> p >> e >> a) && (f + p + e + a)){
- vector<Program> programs[p + 1];
- for(int i = 0; i < p; i++){
- for(int j = 0; j < f; j++){
- cin >> tmpE >> tmpJ;
- programs[i].push_back(Program(tmpE, tmpJ));
- }
- }
- ll ans = 0;
- int actual_freq = 1;
- for(int i = 0; i < p; i++){
- int miN = INF;
- int idx = actual_freq;
- for(int j = 0; j < f; j++){
- ll prod = programs[i][j].power * programs[i][j].time;
- if(prod < miN){
- if(j + 1 != actual_freq){
- if(prod + (e * a) < miN){
- miN = prod + (e * a);
- idx = j + 1;
- }
- }else{
- miN = prod;
- idx = j + 1;
- }
- }
- }
- actual_freq = idx;
- ans += miN;
- }
- cout << ans << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment