Submission
Id | When | Author | Problem | Language | CPU | Memory | Verdict |
---|---|---|---|---|---|---|---|
17898 | 2024-04-24 04:20:43 | dnt | Bonus Project | Java | 103 ms | 38584 kb | Runtime Error - 1 |
Test Cases
CPU | Memory | Verdict | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
1 | 103 ms | 38584 kb | Runtime Error | ||||||||
2 | - | - | Skipped | ||||||||
3 | - | - | Skipped | ||||||||
4 | - | - | Skipped | ||||||||
5 | - | - | Skipped | ||||||||
Source Code
program.java
import java.util.*; public class Main { static class Employee { int id; long accountBalance; List<Employee> subordinates; public Employee(int id, long accountBalance) { this.id = id; this.accountBalance = accountBalance; this.subordinates = new ArrayList<>(); } } static void distributeProjects(Employee leader, int projectLeader, int bonusAmount) { if (leader.id == projectLeader) { leader.accountBalance += 2 * bonusAmount; } else { leader.accountBalance += bonusAmount; } for (Employee subordinate : leader.subordinates) { distributeProjects(subordinate, projectLeader, bonusAmount); } } static void propagateBonus(Employee leader) { long bonus = leader.accountBalance / 2; for (Employee subordinate : leader.subordinates) { subordinate.accountBalance += bonus; propagateBonus(subordinate); } } int t = scanner.nextInt(); // Number of test cases while (t-- > 0) { int n = scanner.nextInt(); // Number of employees int q = scanner.nextInt(); // Number of projects Employee[] employees = new Employee[n + 1]; for (int i = 1; i <= n; i++) { long initialBalance = scanner.nextLong(); employees[i] = new Employee(i, initialBalance); } for (int i = 0; i < n - 1; i++) { int a = scanner.nextInt(); int b = scanner.nextInt(); employees[a].subordinates.add(employees[b]); } for (int i = 0; i < q; i++) { int projectLeader = scanner.nextInt(); int bonusAmount = scanner.nextInt(); distributeProjects(employees[projectLeader], projectLeader, bonusAmount); } propagateBonus(employees[1]); for (int i = 1; i <= n; i++) { } } } }