CF967D Resource Distribution

Ideas:

Among a bunch of servers, the one with the least resources is the "bottleneck", which leads to the idea of ​​greed.

First, all servers are sorted according to the number of resources c, and then scanned from beginning to end. For each position, according to x1 and x2, two consecutive server sets are calculated and assigned to task A and task B respectively (the sequence of assigning A and B needs to be enumerated). If it is enough, there is a solution. If all positions fail, there is no solution.

accomplish:

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef pair<int, int> pii;
 4 pii c[300005];
 5 int n, x1, x2;
 6 vector<int> check(int a, int b)
 7 {
 8     bool flg = false;
 9     int tmp, tmp2, l, l2, i = 0;
10     for ( ; i < n; i++)
11     {
12         tmp = c[i].first; l = (a + tmp - 1) / tmp;
13         if (i + l >= n) continue;
14         tmp2 = c[i + l].first; l2 = (b + tmp2 - 1) / tmp2;
15         if (i + l + l2 > n) continue;
16         flg = true; break;
17     }
18     vector<int> ans;
19     if (flg) { ans.push_back(i); ans.push_back(l); ans.push_back(l2); }
20     return ans;
21 }
22 void show(vector<int> & v, bool rev)
23 {
24     vector<int> v1, v2;
25     for (int i = v[0]; i < v[0] + v[1]; i++) v1.push_back(c[i].second);
26     for (int i = v[0] + v[1]; i < v[0] + v[1] + v[2]; i++) v2.push_back(c[i].second);
27     cout << "Yes" << endl;
28     if (rev)
29     {
30         cout << v[2] << " " << v[1] << endl;
31         for (auto it: v2) cout << it << " ";
32         cout << endl;
33         for (auto it: v1) cout << it << " ";
34         cout << endl;
35     }
36     else
37     {
38         cout << v[1] << " " << v[2] << endl;
39         for (auto it: v1) cout << it << " ";
40         cout << endl;
41         for (auto it: v2) cout << it << " ";
42         cout << endl;
43     }
44 }
45 int main()
46 {
47     while (cin >> n >> x1 >> x2)
48     {
49         for (int i = 0; i < n; i++) { cin >>c[i].first; c[i].second = i + 1; }
50         sort(c, c + n);
51         vector<int> ans = check(x1, x2);
52         if (ans.size()) { show(ans, false); continue; }
53         ans = check(x2, x1);
54         if (ans.size()) { show(ans, true); continue; }
55         cout << "No" << endl;
56     }
57     return 0;
58 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116761&siteId=291194637