--- tags: uva --- # Uva12834 - Extreme Terror ## 題目大意 題目給你 每塊地可以收取到的費用、每塊地要上繳的費用、最多可以選擇哪幾塊地不收取費用(也不上繳),要我們找出最多利潤是多少 ## 重點觀念 水題 ## 分析 - 用內建的 sort 就可以了 ## 程式題目碼 ```cpp= #include <algorithm> #include <functional> #include <iostream> using namespace std; int main() { int T; cin >> T; for (int t = 1; t <= T; t++) { int n, k; cin >> n >> k; k = n - k; int profit[n]; for (int i = 0; i < n; i++) { int x; cin >> x; profit[i] = -x; } for (int i = 0; i < n; i++) { int y; cin >> y; profit[i] += y; } sort(profit, profit + n, greater<int>()); long long sum_profit = 0; for (int i = 0; i < n; i++) { if (i < k || profit[i] > 0) { sum_profit += profit[i]; } } cout << "Case " << t << ": "; if (sum_profit > 0) { cout << sum_profit; } else { cout << "No Profit"; } cout << endl; } return 0; } ```