---
layout: post
title:  "[BOJ] 10819. 차이를 최대로"
categories: Algorithm
tags: BOJ
author: goodGid
---
* content
{:toc}

## Problem

Problem URL : **[차이를 최대로](https://www.acmicpc.net/problem/10819)**













![](/assets/img/algorithm/10819_1.png)


---


## [1] Wrong Code (18. 09. 24)

``` cpp
#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]({{site.url}}/Permutation/)에도 정리를 했다.


---
layout: post
title:  "[BOJ] 10819. 차이를 최대로"
categories: Algorithm
tags: BOJ
author: goodGid
---
* content
{:toc}

## Problem

Problem URL : **[차이를 최대로](https://www.acmicpc.net/problem/10819)**













![](/assets/img/algorithm/10819_1.png)


---


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

``` cpp
#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]({{site.url}}/Permutation/)에도 정리를 했다.


Fix typo :: 오타 수정
Fix typo :: 오타 수정
