当前位置: 首页 > news >正文

Reading Books(Sorting and Searching)

题目描述

There are n books, and Kotivalo and Justiina are going to read them all. For each book, you know the time it takes to read it.
They both read each book from beginning to end, and they cannot read a book at the same time. What is the minimum total time required?

输入

The first input line has an integer n(1 ≤ n ≤ 2\times10^5): the number of books.
The second line has n integers t1,t2,...,tn(1 ≤ ti ≤ 10^9): the time required to read each book.

输出

Print one integer: the minimum total time.

样例输入
3
2 8 3
样例输出
16

思路分析

阅读所需最短可能时间为所有书籍所需阅读时间的和total。

假设将每本书所需阅读时间按升序排序,A从所需时间最短的书籍开始读,B从所需时间最长的书籍开始阅读。如果A读完了前n-1本书,而B还未读完第n本书,那么两人均读完这n本书所花费的时间就大于total,为t[n]*2。

代码
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,t,total;
int main(){ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);cin>>n;vector<ll>t(n,0);for(ll i=0;i<n;i++){cin>>t[i];total+=t[i];}sort(t.begin(),t.end());cout<<max(total,t[n-1]*2);return 0;
}
http://www.dtcms.com/a/316938.html

相关文章:

  • Redis备份方案:持久化与外部工具全解析
  • G1系统概括
  • 电脑搜索不到公司无线网络
  • 【C# Winform】 Action事件驱动的多层数据传递
  • 【运维部署篇】OpenShift:企业级容器应用平台全面解析
  • 跑yolov5的train.py时,ImportError: Failed to initialize: Bad git executable.
  • Android 之 Kotlin中的kapt
  • io_uring系统调用及示例
  • Houdini Pyro学习笔记
  • [数组]977.有序数组的平方;209.长度最小的子数组
  • VUE+SPRINGBOOT从0-1打造前后端-前后台系统-邮箱重置密码
  • 数据结构——双向链表
  • 【学习嵌入式day-17-数据结构-单向链表/双向链表】
  • C语言:预处理、 库文件、 文件IO
  • Python深度学习:从入门到进阶
  • GPT-1、GPT-2、GPT-3 的区别和联系
  • C语言基础_IDE、进制转换、基本数据类型、输入输出函数、运算符
  • 一文搞定JavaServerPages基础,从0开始写一个登录与人数统计页面
  • 模拟面试总结
  • JSP相关Bug解决
  • Vue.js 教程
  • 市场与销售协同:CRM如何打破部门数据孤岛?
  • 思途Mybatis学习 0805
  • 一个小巧神奇的 USB数据线检测仪
  • LabVIEW 2025 安装攻略(附图文教程)适用于测试与自动控制领域
  • 亚马逊广告进阶指南:大词 VS 长尾词
  • 数据结构2.(双向链表,循环链表及内核链表)
  • 怎么在公司存活下去
  • SAP FI模块凭证增强逻辑的策略
  • 飞算 JavaAI:开启 Java 开发智能自动化新时代