Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int caseNumber = 1;
- while (true)
- {
- int n = int.Parse(Console.ReadLine());
- if (n == 0)
- break;
- Console.WriteLine("Case {0}:", caseNumber);
- string[] parameters = Console.ReadLine().Split(' ');
- int L = int.Parse(parameters[0]);
- int C = int.Parse(parameters[1]);
- int[] topics = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
- int lectureCount = CalculateMinimumLectures(n, L, topics);
- int totalDI = CalculateTotalDI(lectureCount, topics, C);
- Console.WriteLine("Minimum number of lectures: {0}", lectureCount);
- Console.WriteLine("Total dissatisfaction index: {0}", totalDI);
- Console.WriteLine();
- caseNumber++;
- }
- }
- static int CalculateMinimumLectures(int n, int L, int[] topics)
- {
- int lectureCount = 1;
- int totalDuration = 0;
- for (int i = 0; i < n; i++)
- {
- if (totalDuration + topics[i] > L)
- {
- lectureCount++;
- totalDuration = 0;
- }
- totalDuration += topics[i];
- }
- return lectureCount;
- }
- static int CalculateTotalDI(int lectureCount, int[] topics, int C)
- {
- int totalDI = 0;
- for (int i = 0; i < lectureCount; i++)
- {
- int freeTime = topics[i] > 10 ? topics[i] - 10 : 0;
- int DI = freeTime > 0 ? (freeTime - 10) * (freeTime - 10) : 0;
- totalDI += DI;
- }
- if (lectureCount > 1)
- totalDI += C;
- return totalDI;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement