Official
A - 累進課税シミュレーション / Progressive Taxation Simulation Editorial
by
A - 累進課税シミュレーション / Progressive Taxation Simulation Editorial
by
physics0523
初心者の方へ
- AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
- また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
- Python入門 AtCoder Programming Guide for beginners (APG4bPython) は、競技プログラミングのための Python 入門用コンテンツです。
問題文の数式に従って計算すればよいです。
答えは \(32\)bit 符号付き整数型に収まるものの、計算途中の値がこの型に収まらない場合があります。
なので、例えば C++ ではオーバーフローを防止するために long long 型を利用する必要があります。
一連の実装は、 for 文と if 文との組み合わせ等で実現できます。
実装例 (C++):
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
ll N,L,P,Q;
cin >> N >> L >> P >> Q;
while(N--){
ll S;
cin >> S;
if(S<=L){
cout << (S*P)/100 << "\n";
}
else{
cout << (L*P+(S-L)*Q)/100 << "\n";
}
}
return 0;
}
posted:
last update:
