작성일 :

문제 링크

25600번 - Triathlon

설명

참가자들의 점수 중 최댓값을 구하는 문제입니다.


접근법

각 참가자의 점수는 a × (d + g)로 계산합니다.

a가 d + g와 같으면 점수를 두 배로 합니다.

모든 참가자의 점수를 계산하여 최댓값을 출력합니다.



Code

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;

class Program {
  static void Main() {
    var n = int.Parse(Console.ReadLine()!);
    var best = 0;
    for (var i = 0; i < n; i++) {
      var p = Array.ConvertAll(Console.ReadLine()!.Split(), int.Parse);
      var a = p[0]; var d = p[1]; var g = p[2];
      var score = a * (d + g);
      if (a == d + g) score *= 2;
      if (score > best) best = score;
    }
    Console.WriteLine(best);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;

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

  int n; cin >> n;
  int best = 0;
  for (int i = 0; i < n; i++) {
    int a, d, g; cin >> a >> d >> g;
    int score = a * (d + g);
    if (a == d + g) score *= 2;
    if (score > best) best = score;
  }
  cout << best << "\n";

  return 0;
}