Alex and his coins
Practice
2.8 (4 votes)
Math
C++
Observation
Basic math
Problem
67% Success 254 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code
Alex loves to collect coins. He has been doing so since his childhood. He has a total of \(N\) different types of coins, numbered from \(0\) to \(N-1\). The \(i^{th}\) type has \(A[i]\) coins. Since, Alex is free right now, he wishes to keep these coins in order but in a specific way.
Initially no coins are in their place.
In one move, he can keep at most \(K[i]\) coins of the \(i^{th}\) type back in their place. Help him in finding the minimum number of moves it will take to re-order these coins.
Input Format:
- The first line of input contains a single integer \(T\), which denotes the number of test cases.
- The first line of each test case contains an integer \(N\), denoting the number of types of coins.
- The second line of each test case contains \(N\) space-separated integers, where the \(i^{th}\) integer denotes the value of \(A[i]\).
- The third line of each test case contains \(N\) space-separated integers, where the \(i^{th}\) integer denotes the value of \(K[i]\).
Output Format: For each test case, print an integer that denotes the minimum number of moves Alex will take to re-order coins.
Constraints:
\(1 \leq T \leq 10 \\ 1 \leq N \leq 10^5 \\ 1 \leq A[i] \leq 10^9 \\ 1 \leq K[i] \leq 10^9\)
Submissions
Please login to view your submissions
Similar Problems
Points:20
Tags:
Basic ProgrammingEasy
Points:20
2 votes
Tags:
Maths
Points:20
836 votes
Tags:
Ad-HocSimulationEasyMathematicsOpenApprovedMathamatics
Editorial