CODEFORCES 1181A
CODEFORCES
1181A - Chunga Changa
Link to Ques - CodeForces 1181A
Approach
- It's easy to calculate how much coconuts we will buy: (suppose that all money transferred to a single person, this way the number of bought coconuts would be clearly maximal)
- If , then the answer is . The remaining case is a bit harder.
- Let's notice, that there is no need to transfer chizhiks, since the one transferring money could have used chizhiks to buy one more coconut herself.
- Also it's optimal to transfer coins such that the remainder modulo of the receiving part will turn to be exactly zero (we could have simply transfer less for the same effect).
- So the answer is .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.Scanner; public class CF1181A { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long x= sc.nextLong(); long y= sc.nextLong(); long z= sc.nextLong(); long total=(x+y)/z; if((x/z+y/z)<((x+y)/z)) { long change = Math.min(z-(x%z),z-(y%z)); System.out.println(total+" "+change); } else { System.out.println(total+" 0"); } } } |
Comments
Post a Comment