Each person has a yearly income and a number of dependants k.
The taxable amount is the income minus 1,500,000 × k, or 0 if that is negative.
The tax splits the taxable amount into the brackets below, multiplies the part inside each bracket by that bracket's rate, and adds them all up.
The part up to 14,000,000 won is taxed at 6%.
The part over 14,000,000 up to 50,000,000 won is taxed at 15%.
The part over 50,000,000 up to 88,000,000 won is taxed at 24%.
The part over 88,000,000 up to 150,000,000 won is taxed at 35%.
The part over 150,000,000 up to 300,000,000 won is taxed at 38%.
The part over 300,000,000 up to 500,000,000 won is taxed at 40%.
The part over 500,000,000 up to 1,000,000,000 won is taxed at 42%.
The part over 1,000,000,000 won is taxed at 45%.
This sum rounded down to a whole won is the computed tax T (round down once after adding everything, not per bracket).
Next, determine the tax credit C.
If T is 1,300,000 or less, C is T × 55 / 100 rounded down.
If T is more than 1,300,000, C is 715,000 plus (T − 1,300,000) × 30 / 100 rounded down, but at most 740,000.
The tax to pay is T − C.
The marginal rate is the rate (%) of the bracket holding the last won of the taxable amount, or 0 if the taxable amount is 0.
A taxable amount equal to a bracket's upper end belongs to that bracket.
The first line gives the number of people n, and each of the next n lines gives a person's income and k separated by a single space.
For each person, in input order, print T, the tax to pay and the marginal rate (the number only, without a % sign) on one line, separated by single spaces.
Input
1 ≤ n ≤ 1,000, 0 ≤ income ≤ 100,000,000,000, 1 ≤ k ≤ 20, all integers
Output
n lines, each three integers: computed tax, tax to pay, marginal rate
Example 1 · stdin
3
60000000 3
15500000 1
3000000 2
stdout
7560000 6820000 24
840000 378000 6
0 0 0
main.py
Error List00F8 ↓ · ⇧F8 ↑
Input (stdin)
When you run, these lines are fed to input()/stdin in order (the program doesn't stop to ask).
$ Ready
Open this on a computer to write and run code. On mobile you can read the problem and the solutions.
In other languagesShow solutions by language · 8 languages
A progressive tax is a loop that walks the brackets in order and accumulates only the part inside each one. if (base <= low) break; stops when the taxable amount does not pass a bracket's lower end; otherwise add min(base, high) - low times the rate. The most common mistake is multiplying the whole taxable amount by the last bracket's rate (for the example's 55,500,000 won that gives 13,320,000). Stopping with < instead of <= turns the marginal rate into 15 when the taxable amount is exactly 14,000,000. The accumulated value reaches about 4.5 trillion, which does not fit in an int (about 2.1 billion): C and C++ long long (%lld in printf), Java and C# long, and multiply as long too, as in 1_500_000L * k. Python integers have no size limit, and JS, TS and Craykon have a single number type (double) but stay exact below 2^53 (about 9 × 10^15). Multiplying by a real rate such as 0.35 and truncating can lose one won to binary floating-point error: 180 * 0.35 is not 63 but 62.99999999999999, so truncating the 35% part of a taxable amount of 88,000,180 won per bracket gives 62. So accumulate with integer percents and divide by 100 only once at the end with integer division: Python //, integer / in the C family, JS/TS Math.floor(a / 100), Craykon Mathf.Quot(a, 100). The credit is a two-way if-else: Python if … else:, Craykon if … else. The 740,000 won limit is one more min.
Pythonmain.py · 37 lines
import sys# (구간 아래 끝, 위 끝, 세율 %) — 아래 끝 초과 위 끝 이하인 부분에 그 세율BRACKETS = [ (0, 14_000_000, 6), (14_000_000, 50_000_000, 15), (50_000_000, 88_000_000, 24), (88_000_000, 150_000_000, 35), (150_000_000, 300_000_000, 38), (300_000_000, 500_000_000, 40), (500_000_000, 1_000_000_000, 42), (1_000_000_000, 10**18, 45),]data = sys.stdin.read().split()n = int(data[0])out = []for i in range(n): income = int(data[1 + 2 * i]) k = int(data[2 + 2 * i]) base = max(income - 1_500_000 * k, 0) total = 0 # 세율을 곱한 값을 쌓는다(100으로는 마지막에 한 번 나눈다) rate = 0 for low, high, r in BRACKETS: if base <= low: break total += (min(base, high) - low) * r rate = r tax = total // 100 if tax <= 1_300_000: credit = tax * 55 // 100 else: credit = min(715_000 + (tax - 1_300_000) * 30 // 100, 740_000) out.append(f"{tax} {tax - credit} {rate}")print("\n".join(out))
JavaScriptmain.js · 39 lines
const data = require("fs").readFileSync(0, "utf8").trim().split(/\s+/).map(Number);// [구간 아래 끝, 위 끝, 세율 %] — 아래 끝 초과 위 끝 이하인 부분에 그 세율const BRACKETS = [ [0, 14000000, 6], [14000000, 50000000, 15], [50000000, 88000000, 24], [88000000, 150000000, 35], [150000000, 300000000, 38], [300000000, 500000000, 40], [500000000, 1000000000, 42], [1000000000, Infinity, 45],];const n = data[0];const out = [];for (let i = 0; i < n; i++) { const income = data[1 + 2 * i]; const k = data[2 + 2 * i]; const base = Math.max(income - 1500000 * k, 0); let total = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 2^53 안에서 정확) let rate = 0; for (const [low, high, r] of BRACKETS) { if (base <= low) break; total += (Math.min(base, high) - low) * r; rate = r; } const tax = Math.floor(total / 100); let credit; if (tax <= 1300000) { credit = Math.floor((tax * 55) / 100); } else { credit = Math.min(715000 + Math.floor(((tax - 1300000) * 30) / 100), 740000); } out.push(`${tax} ${tax - credit} ${rate}`);}console.log(out.join("\n"));
TypeScriptmain.ts · 40 lines
import { readFileSync } from "node:fs";const data: number[] = readFileSync(0, "utf8").trim().split(/\s+/).map(Number);// [구간 아래 끝, 위 끝, 세율 %] — 아래 끝 초과 위 끝 이하인 부분에 그 세율const BRACKETS: [number, number, number][] = [ [0, 14000000, 6], [14000000, 50000000, 15], [50000000, 88000000, 24], [88000000, 150000000, 35], [150000000, 300000000, 38], [300000000, 500000000, 40], [500000000, 1000000000, 42], [1000000000, Infinity, 45],];const n: number = data[0];const out: string[] = [];for (let i = 0; i < n; i++) { const income: number = data[1 + 2 * i]; const k: number = data[2 + 2 * i]; const base: number = Math.max(income - 1500000 * k, 0); let total = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 2^53 안에서 정확) let rate = 0; for (const [low, high, r] of BRACKETS) { if (base <= low) break; total += (Math.min(base, high) - low) * r; rate = r; } const tax: number = Math.floor(total / 100); let credit: number; if (tax <= 1300000) { credit = Math.floor((tax * 55) / 100); } else { credit = Math.min(715000 + Math.floor(((tax - 1300000) * 30) / 100), 740000); } out.push(`${tax} ${tax - credit} ${rate}`);}console.log(out.join("\n"));
JavaMain.java · 41 lines
import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.util.StringTokenizer;public class Main { // 구간 아래 끝과 세율 % — 아래 끝 초과 다음 아래 끝 이하인 부분에 그 세율 static final long[] LOW = {0L, 14_000_000L, 50_000_000L, 88_000_000L, 150_000_000L, 300_000_000L, 500_000_000L, 1_000_000_000L}; static final int[] RATE = {6, 15, 24, 35, 38, 40, 42, 45}; public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine().trim()); StringBuilder out = new StringBuilder(); for (int i = 0; i < n; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); long income = Long.parseLong(st.nextToken()); int k = Integer.parseInt(st.nextToken()); long base = Math.max(income - 1_500_000L * k, 0L); long total = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 int로는 넘친다) int rate = 0; for (int b = 0; b < LOW.length; b++) { if (base <= LOW[b]) break; long high = b + 1 < LOW.length ? LOW[b + 1] : Long.MAX_VALUE; total += (Math.min(base, high) - LOW[b]) * RATE[b]; rate = RATE[b]; } long tax = total / 100; long credit; if (tax <= 1_300_000) { credit = tax * 55 / 100; } else { credit = Math.min(715_000 + (tax - 1_300_000) * 30 / 100, 740_000); } out.append(tax).append(' ').append(tax - credit).append(' ').append(rate).append('\n'); } System.out.print(out); }}
C#Main.cs · 45 lines
using System;using System.Text;class Program{ // 구간 아래 끝과 세율 % — 아래 끝 초과 다음 아래 끝 이하인 부분에 그 세율 static readonly long[] Low = { 0L, 14_000_000L, 50_000_000L, 88_000_000L, 150_000_000L, 300_000_000L, 500_000_000L, 1_000_000_000L }; static readonly int[] Rate = { 6, 15, 24, 35, 38, 40, 42, 45 }; static void Main() { int n = int.Parse(Console.ReadLine().Trim()); var sb = new StringBuilder(); for (int i = 0; i < n; i++) { string[] p = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries); long income = long.Parse(p[0]); int k = int.Parse(p[1]); long baseAmount = Math.Max(income - 1_500_000L * k, 0L); long total = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 int로는 넘친다) int rate = 0; for (int b = 0; b < Low.Length; b++) { if (baseAmount <= Low[b]) break; long high = b + 1 < Low.Length ? Low[b + 1] : long.MaxValue; total += (Math.Min(baseAmount, high) - Low[b]) * Rate[b]; rate = Rate[b]; } long tax = total / 100; long credit; if (tax <= 1_300_000) { credit = tax * 55 / 100; } else { credit = Math.Min(715_000 + (tax - 1_300_000) * 30 / 100, 740_000); } sb.Append(tax).Append(' ').Append(tax - credit).Append(' ').Append(rate).Append('\n'); } Console.Write(sb); }}
C++main.cpp · 36 lines
#include <algorithm>#include <array>#include <iostream>#include <limits>int main() { // 구간 아래 끝과 세율 % — 아래 끝 초과 다음 아래 끝 이하인 부분에 그 세율 const std::array<long long, 8> low = {0LL, 14000000LL, 50000000LL, 88000000LL, 150000000LL, 300000000LL, 500000000LL, 1000000000LL}; const std::array<int, 8> rates = {6, 15, 24, 35, 38, 40, 42, 45}; int n; std::cin >> n; for (int i = 0; i < n; i++) { long long income; int k; std::cin >> income >> k; long long base = std::max(income - 1500000LL * k, 0LL); long long total = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 int로는 넘친다) int rate = 0; for (int b = 0; b < 8; b++) { if (base <= low[b]) break; long long high = b + 1 < 8 ? low[b + 1] : std::numeric_limits<long long>::max(); total += (std::min(base, high) - low[b]) * rates[b]; rate = rates[b]; } long long tax = total / 100; long long credit; if (tax <= 1300000) { credit = tax * 55 / 100; } else { credit = std::min(715000 + (tax - 1300000) * 30 / 100, 740000LL); } std::cout << tax << ' ' << tax - credit << ' ' << rate << '\n'; }}
Cmain.c · 38 lines
#include <stdio.h>/* 구간 아래 끝과 세율 % — 아래 끝 초과 다음 아래 끝 이하인 부분에 그 세율 */static const long long LOW[8] = {0LL, 14000000LL, 50000000LL, 88000000LL, 150000000LL, 300000000LL, 500000000LL, 1000000000LL};static const int RATE[8] = {6, 15, 24, 35, 38, 40, 42, 45};int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; i++) { long long income; int k; scanf("%lld %d", &income, &k); long long base = income - 1500000LL * k; if (base < 0) base = 0; long long total = 0; /* 세율을 곱한 값을 쌓는다(최대 약 4.5조라 int로는 넘친다) */ int rate = 0; for (int b = 0; b < 8; b++) { if (base <= LOW[b]) break; long long top = base; if (b + 1 < 8 && LOW[b + 1] < top) top = LOW[b + 1]; total += (top - LOW[b]) * RATE[b]; rate = RATE[b]; } long long tax = total / 100; long long credit; if (tax <= 1300000) { credit = tax * 55 / 100; } else { credit = 715000 + (tax - 1300000) * 30 / 100; if (credit > 740000) credit = 740000; } printf("%lld %lld %d\n", tax, tax - credit, rate); } return 0;}
Craykonmain.cray · 41 lines
// 구간 아래 끝과 세율 % — 아래 끝 초과 다음 아래 끝 이하인 부분에 그 세율아래끝 = [0, 14000000, 50000000, 88000000, 150000000, 300000000, 500000000, 1000000000];세율 = [6, 15, 24, 35, 38, 40, 42, 45];n = Console.ReadLine().ToNumber();for (i = 0; i < n; i++){ p = Console.ReadNumbers(); 소득 = p[0]; k = p[1]; 과세표준 = Mathf.Max(소득 - 1500000 * k, 0); 합 = 0; // 세율을 곱한 값을 쌓는다(최대 약 4.5조라 2^53 안에서 정확) 한계세율 = 0; for (b = 0; b < 8; b++) { if (과세표준 <= 아래끝[b]) { break; } 위끝 = 과세표준; if (b + 1 < 8) { 위끝 = Mathf.Min(과세표준, 아래끝[b + 1]); } 합 += (위끝 - 아래끝[b]) * 세율[b]; 한계세율 = 세율[b]; } 세액 = Mathf.Quot(합, 100); 공제 = 0; if (세액 <= 1300000) { 공제 = Mathf.Quot(세액 * 55, 100); } else { 공제 = Mathf.Min(715000 + Mathf.Quot((세액 - 1300000) * 30, 100), 740000); } Console.WriteLine(세액 + " " + (세액 - 공제) + " " + 한계세율);}