torus711 のアレ

主に競技プログラミングの問題について書きます.PC 以外だと数式が表示されないかもしれないです

Codeforces #156, Division 2, A : Greg's Workout

概要

三種類のトレーニングを順に(循環する)実行していく。
i 番目に実行されるトレーニングの反復回数がそれぞれ与えられるので、最も多く実行されるトレーニングを求めよ。

解法

数えるだけ。

コード

typedef vector<int> VI;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )
#define ALL( c ) (c).begin(), (c).end()

const string res[] = { "chest", "biceps", "back" };

int main()
{
	cin.tie( 0 );
	ios::sync_with_stdio( false );

	int n;
	cin >> n;

	VI counts( 3, 0 );

	REP( i, 0, n )
	{
		int a;
		cin >> a;

		counts[ i % 3 ] += a;
	}

	cout << res[ max_element( ALL( counts ) ) - counts.begin() ] << endl;

	return 0;
}