B. Emotes
emote가 a개 주어지고, b번 emote를 사용하여 최대값을 구하는 문제이다.
이때, 같은 emote는 연속으로 c번 사용 가능하다는 제약이 있다.
같은 값을 가지더라도, index가 다르면 다른 emote로 취급한다고 한다.
emote는 적어도 2개 이상 입력으로 들어오기 때문에, 처음 2개의 값을 기준으로 maxv와 submaxv값을 설정한다.
나머지 모든 emote에 대해서 가장 큰값과 그 다음으로 같거나 큰값을 추출한 뒤, 아래과 같이 계산한다.
$$Answer = (maxv * c + submaxv) * (b / (c+1)) + (maxv * (b \% (c+1)))$$
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | #include <bits/stdc++.h> using namespace std; typedef long long ll; ll a, b, c; ll maxv, submaxv, temp; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> a >> b >> c >> maxv >> submaxv; if (maxv < submaxv) swap(maxv, submaxv); for (int i = 2; i < a; i++) { cin >> temp; if (maxv <= temp) { submaxv = maxv; maxv = temp; } else if (submaxv < temp) submaxv = temp; } cout << (maxv*c + submaxv) * (b / (c + 1)) + maxv * (b % (c + 1)); return 0; } | cs |
'Competition > codeforces' 카테고리의 다른 글
Codeforces Round #535 (Div. 3) A. Two distinct points (0) | 2019.03.27 |
---|---|
Codeforces Global Round 1 A. Parity (0) | 2019.03.27 |
CodeCraft-19 and Codeforces Round #537 (Div. 2) A. Superhero Transformation (0) | 2019.03.27 |
Codeforces Round #539 (Div. 2) A. Sasha and His Trip (0) | 2019.03.27 |
Codeforces Round #538 (Div. 2) A. Got Any Grapes? (0) | 2019.03.27 |