fragment-header
fragment-markdown
홈
로그인
로그아웃
내 블로그
설정
로그인
백준 21127 (C++) Binary Supersonic Utahraptors
최초 업로드: 2025-09-23 01:11:34
최근 수정 시간: 2025-09-23 01:37:03
게시자: rlatjwls3333
카테고리: 백준
조회수: 5
# [Silver II] Binary Supersonic Utahraptors [문제 링크](https://www.acmicpc.net/problem/21127) ## 문제 설명 <p>Alexey and Boris are playing a game called <em>Binary Supersonic Utahraptors</em> (BSU). </p> <p>Initially, Alexey has $n$ utahraptors, and Boris has $m$ utahraptors. Each utahraptor is either yellow or red.</p> <p>Then, the players take $k$ turns described by integers $s_1, s_2, \ldots, s_k$. The $i$-th turn is performed as follows. First, Alexey chooses $s_i$ utahraptors that belong to him and gives them to Boris. Then, Boris chooses $s_i$ utahraptors that belong to him (the utahraptors that Alexey has just given to him may also be chosen) and gives them to Alexey.</p> <p>When the $k$ moves are done, the score of the game is calculated. The score is equal to $|a_y - b_r|$, where $a_y$ is the number of yellow utahraptors Alexey has, and $b_r$ is the number of red utahraptors Boris has. Alexey's goal is to minimize the score, and Boris wants to maximize it.</p> <p>Write a program that calculates the score of the game if both players use their optimal strategies.</p> ## 입력 <p>The first line contains three integers $n$, $m$, $k$, the number of utahraptors obtained by Alexey, the number of utahraptors obtained by Boris, and the number of turns in the game ($1 \le n, m, k \le 3 \cdot 10^5$).</p> <p>The second line contains $n$ integers $a_i$, denoting Alexey's utahraptors ($0 \le a_i \le 1$). If $a_i = 0$, then the $i$-th utahraptor is yellow, otherwise the $i$-th utahraptor is red.</p> <p>The third line contains $m$ integers $b_i$, denoting Boris's utahraptors in the same manner as described above ($0 \le b_i \le 1$).</p> <p>The fourth line contains $k$ integers $s_i$, describing the numbers of utahraptors that players give to each other on the $i$-th turn ($1 \le s_i \le \min\{n, m\}$).</p> ## 출력 <p>Print the score of the game if both players play optimally.</p> ## 풀이 최선을 다해 바꾸는 것은 바꾸지 않는 것과 동일합니다. prof. a의 점수를 S, b의 점수를 T라고 가정하자. a가 b에게 k개의 1을 준다면 a의 점수는 S - ($s_i$-k), b의 점수는 T+k이 된다. 그 후 b가 a에게 l개의 0을 준다면 a의 점수는 S-($s_i$-k) + l, b의 점수는 T-($s_i$-l) + k이 된다. 최종 점수는 abs(S-($s_i$-k)+l - (T-($s_i$-l)+k))이고 이는 초기 점수인 abs(S-T)와 동일하다. ``` c++ #include<bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n, m, k; cin >> n >> m >> k; int aScore=0, bScore=0; while(n--) { int a; cin >> a; aScore += !a; } while(m--) { int b; cin >> b; bScore += b; } cout << abs(aScore-bScore); } ```