Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream inp_file("/home/xu/CLionProjects/BotaemVsesib/input.txt");
- ofstream out_file("output.txt");
- unsigned int n, m;
- unsigned long long wishes[200][2]; // [num][price]
- unsigned long long nums_of_dishes[20][200];
- long long benefit_of_dishes[20];
- unsigned int count_of_dishes[20];
- unsigned long long boughted_nums[200];
- int c_of_boughted_nums = 0;
- bool is_need(unsigned long long num){
- bool res = false;
- for(int i = 0; i < n; i++){
- if(wishes[i][0] == num){
- res = true;
- break;
- }
- }
- return res;
- }
- bool is_bouhgt(unsigned long long num){
- bool res = false;
- for(int i = 0; i < c_of_boughted_nums; i++){
- if(boughted_nums[i] == num){
- res = true;
- break;
- }
- }
- return res;
- }
- unsigned long long get_price_num(unsigned long long num){
- unsigned long long res = 0;
- for(int i = 0; i < n; i++){
- if(wishes[i][0] == num && !is_bouhgt(num)){
- res = wishes[i][1];
- break;
- }
- }
- return res;
- }
- void add_to_bought_mas(int num){
- for(int i = 0; i < count_of_dishes[num]; i++){
- cout << num << " " << i << " " << nums_of_dishes[num][i] << " " << boughted_nums[c_of_boughted_nums] << endl;
- boughted_nums[c_of_boughted_nums] = nums_of_dishes[num][i];
- c_of_boughted_nums++;
- }
- }
- int main() {
- unsigned long long buf;
- long long price_orig;
- int delta_i = 0;
- inp_file >> n;
- for(int i = 0; i < n; i++){inp_file >> wishes[i][0]; inp_file >> wishes[i][1];}
- inp_file >> m;
- for(int i = 0; i < m; i++){
- inp_file >> count_of_dishes[i];
- inp_file >> benefit_of_dishes[i];
- price_orig = 0;
- delta_i = 0;
- //cout << count_of_dishes[i] << endl;
- for(int k = 0; k < count_of_dishes[i]; k++){
- inp_file >> buf;
- if(is_need(buf)) {
- nums_of_dishes[i][k] = buf;
- price_orig += get_price_num(buf);
- }
- else delta_i++;
- }
- count_of_dishes[i] -= delta_i;
- benefit_of_dishes[i] = price_orig - benefit_of_dishes[i];
- }
- long long max;
- while(max >= 0) {
- max = 0;
- for (int i = 0; i < m; i++) {
- if(max <= get_price_num(i)) {max = get_price_num(i); cout << count_of_dishes[i] << endl; add_to_bought_mas(i);}
- }
- }
- cout << n << " " << m << endl;
- for(int i = 0; i < c_of_boughted_nums; i++){
- cout << boughted_nums[i] << endl;
- }
- inp_file.close();
- out_file.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement