Mushrooms on Half a Pizza
Time limit1sMemory limit32 MB
Given mushroom counts on eight circular pizza slices, find the largest total on any four consecutive slices.
- Level
Easy2 of 10
- Topics
- Brute force, Array
- Solved
- No attempts yet
Problem
After eating every cookie in the witch's house, Hansel and Gretel ordered a jumbo pizza. It arrived soon after, already cut into eight slices. The two of them split the pizza in half, so each takes a full half circle, meaning four consecutive slices.
Gretel loves mushrooms and wants as many as she can get. The slices carry different numbers of mushrooms, so Gretel asked Hansel to cut the pizza in half in the way that gives her share the most mushrooms.
Given the number of mushrooms on each of the eight slices, find the largest total number of mushrooms Gretel can get. The slices form a circle, so the eighth slice and the first slice are neighbors.
Input
Eight lines follow, each holding one integer (, ). is the number of mushrooms on the -th slice, with the slices listed in clockwise order.
Output
Print the largest total number of mushrooms Gretel can get on one line.