Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- 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;
- }
- 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;
- }
- int main()
- {
- int caseNumber = 1;
- while (1)
- {
- int n, L, C;
- scanf("%d", &n);
- if (n == 0)
- break;
- printf("Case %d:\n", caseNumber);
- scanf("%d %d", &L, &C);
- int topics[n];
- for (int i = 0; i < n; i++)
- {
- scanf("%d", &topics[i]);
- }
- int lectureCount = calculateMinimumLectures(n, L, topics);
- int totalDI = calculateTotalDI(lectureCount, topics, C);
- printf("Minimum number of lectures: %d\n", lectureCount);
- printf("Total dissatisfaction index: %d\n\n", totalDI);
- caseNumber++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement