Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.math.BigDecimal;
- import java.math.BigInteger;
- import java.math.RoundingMode;
- import java.util.*;
- public class _2ndDragonAccounting {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- BigDecimal capital = new BigDecimal(scanner.nextLine());
- LinkedHashMap<Integer,LinkedHashMap<BigDecimal,BigInteger>> employees = new LinkedHashMap<>();
- boolean bancrucy = false;
- boolean firingOver = false;
- int firingDay=1;
- BigInteger allfired = BigInteger.ZERO;
- BigInteger allhired = BigInteger.ZERO;
- int dayCounter = 1;
- String input = scanner.nextLine();
- while (true){
- if(input.equals("END")){
- break;
- }
- String[] commands = input.split(";");
- BigInteger hired = new BigInteger(commands[0]);
- BigInteger fired = new BigInteger(commands[1]);
- BigDecimal newSalary = new BigDecimal(commands[2]);
- if(!employees.containsValue(hired)){
- employees.put(dayCounter,new LinkedHashMap<>());
- }
- employees.get(dayCounter).put(newSalary,hired);
- allhired = allhired.add(hired);
- if(dayCounter%30==0){
- //paySalary
- for (int day : employees.keySet()) {
- for (BigDecimal money : employees.get(day).keySet()) {
- BigInteger countWorkers = employees.get(day).get(money);
- BigDecimal currentMoney = money.setScale(9, RoundingMode.UP);
- BigDecimal dailySalary = currentMoney.divide(new BigDecimal(30), 9, BigDecimal.ROUND_UP);
- BigDecimal currentSalary=BigDecimal.ZERO;
- if (day < 30) {
- currentSalary = currentSalary.add(dailySalary.multiply(new BigDecimal(day)));
- }
- else {
- if(day>365){
- int years = (dayCounter-day)/365;
- for (int i = 0; i < years; i++) {
- dailySalary=dailySalary.multiply(BigDecimal.valueOf(0.006));
- }
- }
- currentSalary = currentSalary.add(dailySalary.multiply(new BigDecimal(30)));
- }
- currentSalary=currentSalary.multiply(new BigDecimal(countWorkers));
- capital=capital.subtract(currentSalary.setScale(7, BigDecimal.ROUND_FLOOR));
- }
- }
- }
- //firing
- allfired = allfired.add(fired);
- while (!firingOver){
- for (BigDecimal bigDecimal : employees.get(firingDay).keySet()) {
- if(fired.compareTo(employees.get(firingDay).get(bigDecimal))>0){
- fired=fired.subtract(employees.get(firingDay).get(bigDecimal));
- employees.get(firingDay).replace(bigDecimal,BigInteger.ZERO);
- }
- else{
- BigInteger oldValue = employees.get(firingDay).get(bigDecimal);
- employees.get(firingDay).replace(bigDecimal,oldValue.subtract(fired));
- firingOver=true;
- }
- }
- }
- for (int i = 3; i < commands.length; i++) {
- String command = commands[i];
- String money = command.substring(command.indexOf(":")+1);
- BigDecimal currentIncomeOrExpense =new BigDecimal(money);
- if(command.contains("Product development")||command.contains("Unconditional funding")){
- //incomes
- capital = capital.add(currentIncomeOrExpense);
- }
- else{
- //expense
- capital=capital.subtract(currentIncomeOrExpense);
- }
- }
- if(capital.compareTo(BigDecimal.ZERO)<0){
- bancrucy=true;
- break;
- }
- dayCounter++;
- input = scanner.nextLine();
- }
- if(bancrucy){
- System.out.println("BANKRUPTCY: " + (capital.multiply(BigDecimal.valueOf(-1)).setScale(4, RoundingMode.FLOOR)));
- return;
- }
- System.out.println(allhired.subtract(allfired)+" "+ capital.setScale(4, RoundingMode.FLOOR));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement