以下の内容はhttps://blog.hamayanhamayan.com/entry/2019/01/14/110627より取得しました。


Roman and Browser [Codeforces Round #532 (Div. 2) A]

https://codeforces.com/contest/1100/problem/A

N要素の配列Aがある。
ある数Kもある。
ここである数Bを定めて、BからK個飛ばしで到達できる要素以外の数、
つまり、B+iK(iは整数)の添字の要素以外の数の総和を求める。
この総和の絶対値の最大値は?

K,N≦100
 
 
 
 
 
 
 
 
 
 
 
 

解法

https://codeforces.com/contest/1100/submission/48331935

Bを全探索する。
すると、飛ばす要素はabs(i-b)%K==0を満たすので、それ以外を足して、総和の絶対値の最大を求める。

int N, K, A[101];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> A[i];

    int ans = 0;
    rep(b, 0, N) {
        int sm = 0;
        rep(i, 0, N) if (0 < abs(i - b) % K) sm += A[i];
        chmax(ans, abs(sm));
    }
    cout << ans << endl;
}



以上の内容はhttps://blog.hamayanhamayan.com/entry/2019/01/14/110627より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14