Advertisement
CR7CR7

Assignment

Jun 7th, 2023
965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         int caseNumber = 1;
  8.  
  9.         while (true)
  10.         {
  11.             int n = int.Parse(Console.ReadLine());
  12.             if (n == 0)
  13.                 break;
  14.  
  15.             Console.WriteLine("Case {0}:", caseNumber);
  16.  
  17.             string[] parameters = Console.ReadLine().Split(' ');
  18.             int L = int.Parse(parameters[0]);
  19.             int C = int.Parse(parameters[1]);
  20.  
  21.             int[] topics = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
  22.  
  23.             int lectureCount = CalculateMinimumLectures(n, L, topics);
  24.             int totalDI = CalculateTotalDI(lectureCount, topics, C);
  25.  
  26.             Console.WriteLine("Minimum number of lectures: {0}", lectureCount);
  27.             Console.WriteLine("Total dissatisfaction index: {0}", totalDI);
  28.             Console.WriteLine();
  29.  
  30.             caseNumber++;
  31.         }
  32.     }
  33.  
  34.     static int CalculateMinimumLectures(int n, int L, int[] topics)
  35.     {
  36.         int lectureCount = 1;
  37.         int totalDuration = 0;
  38.  
  39.         for (int i = 0; i < n; i++)
  40.         {
  41.             if (totalDuration + topics[i] > L)
  42.             {
  43.                 lectureCount++;
  44.                 totalDuration = 0;
  45.             }
  46.  
  47.             totalDuration += topics[i];
  48.         }
  49.  
  50.         return lectureCount;
  51.     }
  52.  
  53.     static int CalculateTotalDI(int lectureCount, int[] topics, int C)
  54.     {
  55.         int totalDI = 0;
  56.  
  57.         for (int i = 0; i < lectureCount; i++)
  58.         {
  59.             int freeTime = topics[i] > 10 ? topics[i] - 10 : 0;
  60.             int DI = freeTime > 0 ? (freeTime - 10) * (freeTime - 10) : 0;
  61.             totalDI += DI;
  62.         }
  63.  
  64.         if (lectureCount > 1)
  65.             totalDI += C;
  66.  
  67.         return totalDI;
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement