比赛 2024暑假C班集训5 评测结果 AWWTTTTTTT
题目名称 任务 最终得分 10
用户昵称 彭欣越 运行时间 7.000 s
代码语言 C++ 内存使用 4.03 MiB
提交时间 2024-07-05 11:51:23
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int n,ans=1e8+10;
  4. struct node {
  5. int x,y;
  6. }a[2010];
  7. bool cmp (node x,node y) {
  8. return x.x-x.y<y.x-y.y;
  9. }
  10. void dfs (int idx,int res1,int res2) {
  11. if (idx==n) {
  12. ans=min(ans,max(res1+a[idx].x,res2));
  13. ans=min(ans,max(res1,res2+a[idx].y));
  14. return;
  15. }
  16. if (res1+a[idx].x<ans) dfs(idx+1,res1+a[idx].x,res2);
  17. if (res2+a[idx].y<ans) dfs(idx+1,res1,res2+a[idx].y);
  18. return;
  19. }
  20. int main () {
  21. freopen("task.in","r",stdin);
  22. freopen("task.out","w",stdout);
  23. cin >> n;
  24. for (int i=1;i<=n;i++) cin >> a[i].x >> a[i].y;
  25. //sort(a+1,a+n+1,cmp);
  26. dfs(1,0,0);
  27. cout << ans <<endl;
  28. return 0;
  29. }