题解:P15055 [UOI 2023 II Stage] Gallery

· · 题解

题目传送门

题目大意

给定三个整数 a, b, c,选择其中两个数相加,求能得到的最大和。

解题思路

  1. 列出所有可能的两两组合:a+ba+cb+c
  2. 计算这三个组合的和;
  3. 找出这三个和中的最大值,即为答案。

时间复杂度为 O(1),空间复杂度也为 O(1)

参考代码

#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main() {
    cin>>a>>b>>c;
    int ans=max({a+b,a+c,b+c});
    cout<<ans;
    return 0;
}

蒟蒻写题解不容易,管理员大大求过。