LoginSignup
1
0

More than 1 year has passed since last update.

Atcoder 解答例 ABC 072 C - Together

Posted at

ABC 072 C - Together 解答例

問題はこちら

解答例が見当たらなかったため、備忘録がてら投稿します。
何かアドバイスがあれば気軽にコメントください。

#include <iostream>
#include <cmath>

using namespace std;


int main() {
    int N;
    int a[100001];
    int input_max = 0;
    int input_min = 100000;

    int count_max = 0;
    int count = 0;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (input_min >= a[i]) input_min = a[i];
        if (input_max <= a[i]) input_max = a[i];
    }


    for (int x = input_min - 1; x <= input_max + 1; x++) {
        count = 0;


        for (int i = 0; i < N; i++) {
            if (abs(x - a[i])<=1) count++;
        }

        if (count_max <= count) count_max = count;
    }

    cout << count_max << endl;
    return 0;
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0