As KEYENCE headquarters have more and more workers, they decided to divide the…
- User
As KEYENCE headquarters have more and more workers, they decided to divide the departments in the headquarters into two groups and stagger their lunch breaks.
KEYENCE headquarters have N departments, and the number of people in the i-th department (1≤i≤N) is
Ki.
When assigning each department to Group A or Group B, having each group take lunch breaks at the same time, and ensuring that the lunch break times of Group A and Group B do not overlap, find the minimum possible value of the maximum number of people taking a lunch break at the same time. In other words, find the minimum possible value of the larger of the following: the total number of people in departments assigned to Group A, and the total number of people in departments assigned to Group
B. Constraints
2≤N≤20
code1≤Ki≤108 All input values are integers.Input
The input is given from Standard Input in the following format:
N
K1
K2
…
KN
Output
Print the minimum possible value of the maximum number of people taking a lunch break at the same time. Sample Input 1 Copy
5 2 3 5 10 12
Sample Output 1 Copy
17
When assigning departments 1, 2, and 5 to Group A, and departments 3 and 4 to Group B, Group A has a total of 2+3+12=17 people, and Group B has a total of 5+10=15 people. Thus, the maximum number of people taking a lunch break at the same time is
It is impossible to assign the departments so that both groups have 16 or fewer people, so print
Sample Input 2 Copy
2 1 1
Sample Output 2 Copy
1
Multiple departments may have the same number of people. Sample Input 3 Copy
6 22 25 26 45 22 31
Sample Output 3 Copy
89
For example, when assigning departments 1, 4, and 5 to Group A, and departments 2, 3, and 6 to Group B, the maximum number of people taking a lunch break at the same time is 89. c++
- Assistant
- User
The manufacturing of a certain product requires N processes numbered
1,2,…,N.
For each process i, there are two types of machines Si and
Ti available for purchase to handle it.
codeMachineSi: Can process Ai products per day per unit, and costs Pi yen per unit. Machine Ti: Can process Bi products per day per unit, and costs
codeQi yen per unit.You can purchase any number of each machine, possibly zero.
Suppose that process i can handle Wi products per day as a result of introducing machines. Here, we define the production capacity as the minimum of W, that is,
- Assistant
- User
去掉注释
- Assistant
当然,可以去掉注释的版本如下:
cpp#include <iostream> #include <vector> using namespace std; bool canAchieveCapacity(int C, int X, const vector<int>& A, const vector<int>& P, const vector<int>& B, const vector<int>& Q, int N) { long long totalCost = 0; for (int i = 0; i < N; ++i) { long long costS = (long long)P[i] * ((C + A[i] - 1) / A[i]); long long costT = (long long)Q[i] * ((C + B[i] - 1) / B[i]); totalCost += min(costS, costT); if (totalCost > X) return false; } return totalCost <= X; } int main() { int N; long long X; cin >> N >> X; vector<int> A(N), P(N), B(N), Q(N); for (int i = 0; i < N; ++i) { cin >> A[i] >> P[i] >> B[i] >> Q[i]; } int low = 0, high = 1e9, maxCapacity = 0; while (low <= high) { int mid = low + (high - low) / 2; if (canAchieveCapacity(mid, X, A, P, B, Q, N)) { maxCapacity = mid; low = mid + 1; } else { high = mid - 1; } } cout << maxCapacity << endl; return 0; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.