公式
A - The bottom of the ninth 解説 by mechanicalpenciI
\(9\) 回表の時点で チーム高橋が \(X\) 点、 チーム青木が \(Y\) 点をとっていたとします。(問題文の制約より \(X\geq Y\) です。)
ここで、\(X,Y\) はそれぞれ、\(X=A_1+A_2+\cdots+A_9\), \(Y=B_1+B_2+\cdots+B_8\) として求められます。
このとき、\(9\) 回裏にチーム青木が取った点数が \((X-Y-1)\) 以下であればチーム高橋の勝ち、\((X-Y)\) であれば引き分け、\((X-Y+1)\) 以上であればチーム青木の勝ちとなります。
よって、チーム青木が勝つために必要な点数の最小値は \((X-Y+1)\) であるので、これを出力すれば良いです。
c++ による実装例:
#include <bits/stdc++.h>
using namespace std;
int main() {
int a=0,b=0,x;
for(int i=0;i<9;i++){
cin>>x;
a+=x;
}
for(int j=0;j<8;j++){
cin>>x;
b+=x;
}
cout<<(a-b+1)<<endl;
return 0;
}
Python による実装例:
A = list(map(int, input().split()))
B = list(map(int, input().split()))
print(sum(A)-sum(B)+1)
投稿日時:
最終更新: