Advertisement
Guest User

AAAAAAAAAAAAAAAAAaaaaaaaaaaAAAAAAAAAAAAAA

a guest
Jan 20th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream inp_file("/home/xu/CLionProjects/BotaemVsesib/input.txt");
  7. ofstream out_file("output.txt");
  8.  
  9. unsigned int n, m;
  10. unsigned long long wishes[200][2]; // [num][price]
  11. unsigned long long nums_of_dishes[20][200];
  12. long long benefit_of_dishes[20];
  13. unsigned int count_of_dishes[20];
  14.  
  15. unsigned long long boughted_nums[200];
  16. int c_of_boughted_nums = 0;
  17.  
  18. bool is_need(unsigned long long num){
  19.     bool res = false;
  20.     for(int i = 0; i < n; i++){
  21.         if(wishes[i][0] == num){
  22.             res = true;
  23.             break;
  24.         }
  25.     }
  26.     return res;
  27. }
  28.  
  29. bool is_bouhgt(unsigned long long num){
  30.     bool res = false;
  31.     for(int i = 0; i < c_of_boughted_nums; i++){
  32.         if(boughted_nums[i] == num){
  33.             res = true;
  34.             break;
  35.         }
  36.     }
  37.     return res;
  38. }
  39.  
  40. unsigned long long get_price_num(unsigned long long num){
  41.     unsigned long long res = 0;
  42.     for(int i = 0; i < n; i++){
  43.         if(wishes[i][0] == num && !is_bouhgt(num)){
  44.             res = wishes[i][1];
  45.             break;
  46.         }
  47.     }
  48.     return res;
  49. }
  50.  
  51. void add_to_bought_mas(int num){
  52.     for(int i = 0; i < count_of_dishes[num]; i++){
  53.         cout << num << " " << i << " " << nums_of_dishes[num][i] << " " << boughted_nums[c_of_boughted_nums] << endl;
  54.         boughted_nums[c_of_boughted_nums] = nums_of_dishes[num][i];
  55.         c_of_boughted_nums++;
  56.     }
  57. }
  58.  
  59. int main() {
  60.  
  61.     unsigned long long buf;
  62.     long long price_orig;
  63.  
  64.     int delta_i = 0;
  65.  
  66.     inp_file >> n;
  67.     for(int i = 0; i < n; i++){inp_file >> wishes[i][0]; inp_file >> wishes[i][1];}
  68.     inp_file >> m;
  69.     for(int i = 0; i < m; i++){
  70.         inp_file >> count_of_dishes[i];
  71.         inp_file >> benefit_of_dishes[i];
  72.         price_orig = 0;
  73.         delta_i = 0;
  74.         //cout << count_of_dishes[i] << endl;
  75.         for(int k = 0; k < count_of_dishes[i]; k++){
  76.             inp_file >> buf;
  77.             if(is_need(buf)) {
  78.                 nums_of_dishes[i][k] = buf;
  79.                 price_orig += get_price_num(buf);
  80.             }
  81.             else delta_i++;
  82.         }
  83.         count_of_dishes[i] -= delta_i;
  84.         benefit_of_dishes[i] = price_orig - benefit_of_dishes[i];
  85.     }
  86.     long long max;
  87.     while(max >= 0) {
  88.         max = 0;
  89.         for (int i = 0; i < m; i++) {
  90.             if(max <= get_price_num(i)) {max = get_price_num(i); cout << count_of_dishes[i] << endl; add_to_bought_mas(i);}
  91.         }
  92.     }
  93.  
  94.     cout << n << " " << m << endl;
  95.  
  96.     for(int i = 0; i < c_of_boughted_nums; i++){
  97.         cout << boughted_nums[i] << endl;
  98.     }
  99.  
  100.     inp_file.close();
  101.     out_file.close();
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement