酷代码 AI
菜单

地图上有n个地方都需要搜寻,搜寻每一处所花费的时间不同。时间紧急,禾木想先搜寻5处耗时最低的地点。请你帮助禾木计算搜寻5处至少要花费多少时间。 输入: 共两行。 第一行为一个整数n(5<n<100)。 第二行为n个整数,依次表示搜寻每个地方需要的时间。 输出: 一个整数,表示搜寻5处至少要花费多少时间。c++

```cpp #include <iostream> #include <vector> #include <algorithm> int main() { int n; std::cin >> n; std::vector<int> times(n); for (int i = 0; i < n; ++i) { std::cin >> times[i]; } std::sort(times.begin(), times.end()); int total = 0; for (int i = 0; i < 5; ++i) { total += times[i]; } std::cout << total << std::endl; return 0; } ``` [2026-01-17 10:20:39 | AI问答 | 133点数解答]

服务商
相关提问
发财导航,免费问AI
实用工具查看更多