Advertisement
ErolKZ

Untitled

Jul 2nd, 2021
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. function solve(input) {
  2.  
  3. let countDays = Number(input[0]);
  4.  
  5. let doctors = 7;
  6.  
  7. let patientsUnattended = 0;
  8.  
  9. let patientsAttended = 0;
  10.  
  11.  
  12. for (let i = 1; i <= countDays; i++) {
  13.  
  14. let current = Number(input[i]);
  15.  
  16.  
  17. if (i % 3 === 0) {
  18.  
  19. if (patientsAttended < patientsUnattended) {
  20.  
  21. doctors += 1;
  22.  
  23. }
  24.  
  25. }
  26.  
  27.  
  28.  
  29. if (doctors >= current) {
  30.  
  31. patientsAttended += current;
  32.  
  33. } else if (doctors < current) {
  34.  
  35. patientsUnattended += current - doctors;
  36. patientsAttended += doctors;
  37.  
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44. }
  45.  
  46.  
  47.  
  48.  
  49. console.log(`Treated patients: ${patientsAttended}.`);
  50. console.log(`Untreated patients: ${patientsUnattended}.`);
  51.  
  52.  
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement