题解:P14613 [2019 KAIST RUN Fall] And the Winner Is... Ourselves!
I_am_kunzi · · 题解
P14613 题解
题目思路
根据题意我们可以发现,罚时只参与最终总时间的计算,而不参与实际比赛时间的计算。所以我们可以先把罚时的部分摘出来计算,然后再考虑剩下的纯解题时间。
这样的话就变成了一个典型的“接水问题”,结论是按照解题时间从小到大排序后计算,证明仿照贪心的证明方法,具体证明过程在下一段。
假设当前有两道题,解题时间分别为
题目代码
#include<bits/stdc++.h>
using namespace std;
int cost[12];
int ans = 0;
signed main()
{
for(int i = 1 ; i <= 11 ; i++)
{
cin >> cost[i];
int V;
cin >> V;
ans += V * 20;
}
sort(cost + 1 , cost + 12);
for(int i = 1 ; i <= 11 ; i++)
{
cost[i] += cost[i - 1];
ans += cost[i];
}
cout << ans << endl;
return 0;
}