본문 바로가기

Algorithm

(C++) - 백준(BOJ) 15969번 : 행복 답

반응형

Code

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
    int n;
    int ans = 0;
    int student[1001];
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> student[i];
    for (int i = 1; i <= n-1; i++)
        for (int j = i + 1; j <= n; j++)
            ans = max(ans, abs(student[i] - student[j]));
    cout << ans << '\n';
}