The battle near the swamp
Time limit: 1 second
Memory limit: 64 MB
____________________________________________________________________________
Gungan: Jar Jar, usen da booma!
Jar Jar: What? Mesa no have a booma!
Gungan: Here. Taken dis one.
_________________________________________________________________________________
In the battle with the Trade Federation, Queen Amidala decided to ask gungans for help. Jar Jar Binks
escorted the Queen and her people to the holy place where they had an agreement. The gungans agreed to
provide their army in order to get the droids of the Federation out from the capital. The gungan ruler Boss
Nass was so grateful for uniting the nations that he appointed Jar Jar a general.
And here they are: two armies lined up along the bank of the swamp. The droids of the Federation are
well-disciplined soldiers. They stand in neat formation, divided into π blocks of π droids each. The gungans
have a foolproof weapon against droids, which is small energy balls called boom booms. One such ball can
disable exactly one droid.
Jar Jar Binks also decided to split his army into π parts and give each part a task to destroy the corresponding
block of droids. Each part received a truck with boom booms. Now help general Binks calculate the number
of boom booms that will be left unused and the number of droids that will survive the attack. You can assume
that when a boom boom is fired at a droid by a gungan, it always hits the target.
Input
The first line of the input contains numbers π and π (1 ≤ π, π ≤ 10 000). The second line contains π numbers ππ (0 ≤ ππ ≤ 100 000) — the number of boom-booms in the π-th truck.
Output
Print two integers — the number of unused boom booms and the number of survived droids.
import java.io.*; public class boomboom{ public static void main(String []args)throws IOException{ BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); int[] j= new int[2],n; String[] s2 = inp.readLine().split(" "); j[0]=Integer.parseInt(s2[0]); j[1]=Integer.parseInt(s2[1]); int[] m= new int[j[0]];int c=0,k=0; String[] s1 = inp.readLine().split(" "); for(int i=0;i<j[0];i++) m[i]=Integer.parseInt(s1[i]); for(int l=0;l<j[0];l++){ int a=j[1]-m[l]; if(a>=0) k=k+a; else c=c-a; } System.out.println(c+" "+k); } }
Comments (0)
Post a Comment