Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- using namespace std;
- struct info
- {
- int group_size;
- int first_element;
- };
- void print_vector(vector<int> & v)
- {
- cout << endl;
- for (int i =0; i < v.size(); ++i)
- cout << v[i] << " ";
- cout << endl;
- }
- int main()
- {
- int n, M, K;
- cin >> n >> M >> K;
- vector<struct info> groups;
- vector<int> mas1(n+1,0);
- vector<int> mas2(n+1,0);
- vector<int> b(n);
- int s1 = 0;
- int s2 = 0;
- double a;
- for (int i=0; i < n; ++i)
- {
- cin >> b[i];
- s1 += b[i];
- a = (double) b[i]/K;
- s2 += ceil(a);
- mas1[i+1] = s1;
- mas2[i+1] = s2;
- }
- print_vector(mas1);
- print_vector(mas2);
- print_vector(b);
- cout << "11" << endl;
- int i = n-1;
- int left, right;
- int sum, len_numbers;
- bool flag;
- int local_max, local_max_idx, k;
- int count_joined, count_alone;
- cout << "11" << endl;
- struct info group;
- int profit = 0;
- int count_groups = 0;
- cout << "11" << endl;
- while (i > 0)
- {
- cout << "Зашёл в вайл, i = " << i << endl;
- if (b[i] % M == 0)
- {
- i -= 1;
- cout << "b[i] = " << b[i] << "- кратко пропускаю" << endl;
- }
- else
- {
- cout << "b[i]= " << b[i] << endl;
- left = (i-M+1) * ((i-M+1) > 0);
- right = i+1;
- sum = mas1[right]-mas1[left];
- cout << "left right = " << left << " " << right << endl;
- cout << " sum = " << sum << endl;
- flag = true;
- while(flag & right-left > 1)
- {
- if (sum % M == 0)
- {
- flag = false;
- cout << "sum кратно, выхожу " << endl;
- }
- else
- {
- count_joined = ceil(sum/K);
- count_alone = mas2[right]-mas2[left];
- cout << "count_joined, count_alone = " << count_joined << " " << count_alone << endl;
- if (local_max <= count_alone-count_joined)
- {
- cout << "update local max ";
- local_max = count_alone-count_joined;
- local_max_idx = left;
- cout << local_max << " " << local_max_idx << endl;
- }
- sum -= b[left];
- left++;
- cout << " new sum = " << sum << endl;
- cout << " new left = " << left << endl;
- }
- }
- if ( (sum % M != 0) & (local_max > 0) )
- {
- cout << " Вышел из вайла за счёт локал макс и он больше 0" << endl;
- group.group_size = right-local_max_idx;
- group.first_element = local_max_idx+1;
- groups.push_back(group);
- profit += local_max;
- i-= group.group_size;
- count_groups++;
- cout << "profit = " << profit << endl;
- cout << "first_element = " << b[local_max_idx] << endl;
- cout << "local_profit = " << local_max << endl;
- }
- else if (sum % M == 0)
- {
- cout << " Вышел из вайла за счёт кратности" << endl;
- count_joined = sum/K;
- count_alone = mas2[right]-mas2[left];
- profit += count_alone-count_joined;
- cout << "count_joined, count_alone = " << count_joined << " " << count_alone << endl;
- group.group_size = right-left;
- group.first_element = left+1;
- groups.push_back(group);
- i -= group.group_size;
- count_groups++;
- cout << "profit = " << profit << endl;
- cout << "first_element = " << b[left] << endl;
- cout << "local_profit = " << count_alone-count_joined << endl;
- }
- else
- i--;
- }
- }
- cout << "end " << endl;
- cout << profit << endl;
- cout << count_groups << endl;
- for (int i = count_groups-1; i > -1; --i)
- cout << groups[i].first_element << " " << groups[i].group_size << endl;
- cout << "end2 " << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment