Deleting arrays
Practice
2.6 (14 votes)
Basic programming
Algorithms
Basics of greedy algorithms
Greedy algorithms
Problem
80% Success 2960 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given two integers \(N\) and \(K\) denoting the number of elements in the array and an arbitrary integer respectively. You can perform the following operations:
- Select an index \(i\).
- Delete the \(i^{th}\) element.
- Delete \(K\) elements to the left of it if they exist or you can delete all the elements if the number of elements to the left of it is less than \(K\).
- Delete \(K\) elements to the right of it if they exist or you can delete all if the number of elements to the right of it is less than \(K\).
Your task is to delete all the elements of the array using the minimum number of provided operations.
Input format
- The first line contains an integer \(T\) denoting the number of test cases.
- The first line of each test case contains a single line containing two space-separated integers \(N\) and \(K\).
Output format
Print \(i^{th}\) \(T\) lines denoting the answer to the \(i^{th}\) test case.
Constraints
\( 1\leq T \leq 20000\)
\(1 \leq N,K \leq 1e9\)
Submissions
Please login to view your submissions
Similar Problems
Points:10
4 votes
Tags:
AlgorithmsBasics of Greedy AlgorithmsC++Greedy Algorithms
Points:10
8 votes
Tags:
Greedy AlgorithmsAlgorithmsBasics of Greedy AlgorithmsGreedy algorithm
Points:10
9 votes
Tags:
Greedy AlgorithmsAlgorithmsStringBasics of Greedy Algorithms
Editorial