F - MaratonIME educates
Problem Description
USP has many lunch options between all the uni cafeterias and the restaurants inside the campus. An option that is usually chosen by MaratonIME seniors is the restaurant in the School of Education, for its good prices and free jelly.
The seniors have years of experience weighting on their shoulders, and therefore have tired legs. So they choose to go to the restaurant by car. Trying to save gas, the seniors always minimize the number of cars necessary to take everyone to the restaurant.
The seniors asked you to help them solve their problems. This morning, n cars with seniors arrived in the university, and all of them want to go to the restaurant. Each car holds up to 5people. What is the minimum number of cars necessary to take everyone to the restaurant to "educate"?
Input
On the first line, an integer n, the number of cars. On the second line, n integers a1, ..., an, how many people arrived in each car.
Limits:
- 1 ≤ n ≤ 105.
- 1 ≤ ai ≤ 5, for all i.
Output
Print a single integer, the minimum number of cars needed to take everyone to the restaurant.
Examples
Input
3 3 4 5Output
3Input
6 1 2 3 4 4 1Output
3
代码如下:
Hint:这题相对来说比较简单,最重要还是安下心来读题。题目给出一路上的学生数量,要求需要多少辆车来承载这些学生。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n, a, sum = 0;
scanf("%d", &n);
while(n--)
{
scanf("%d", &a);
sum += a;
}
if(sum % 5 == 0)
printf("%d\n", sum / 5); // 是5的整数倍,则需要对应车数
else
printf("%d\n", sum / 5 + 1); // 不是5的整数倍则另需要一辆校车
return 0;
}