Codeforces - 599A.Patrick and Shopping

HoJeong Im·2022년 10월 11일
0

Codeforces

목록 보기
12/13

개요

https://codeforces.com/problemset/problem/599/A

  • 3가지의 길을 따라서 다시 집으로 돌아올 때, 가장 최소의 거리를 걸어야 하는 경우를 찾는 과정

    • 같은 출발지와 목적지를 가지는 길을 다시 갈 수 없다는 조건이 존재
  • arr sort => std:sort(a,a+3)과 같이 사용

코드

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    
    int arr[3];
    
    for(int i = 0; i < 3 ; i++){
        cin >> arr[i];
    }
    
    sort(arr, arr+3);
    
    int firstCount = arr[0]*2 + arr[1] * 2;
    
    int secondCount = arr[0]+arr[1]+arr[2];
    
    cout << min(firstCount, secondCount) << endl;
    
    return 0;
}
profile
꾸준함이 제일 빠른 길이었다

0개의 댓글