Gidhub BE Developer

[BOJ] 10819. 차이를 최대로

2018-09-24
goodGid

Problem

Problem URL : 차이를 최대로


[1] Answer Code (18. 09. 24)

#include<iostream>
#include<algorithm>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    int n;
    int arr[10];
    cin >> n ;
    
    for(int i=0; i<n; i++)
        cin >> arr[i];
    
    int ans = -1;
    sort(arr,arr+n);
    
    do {
        int tmp = 0;
        for(int i=0; i<n-1; i++){
            tmp += abs(arr[i] - arr[i+1]);
        }
        ans = max(ans,tmp);
        
    } while (next_permutation(arr, arr+n));
    
    cout << ans << endl;
    return 0;
}

Review

  • 순열과 관련해서 Key Point에도 정리를 했다.

Recommend

Index