Removal
SRM 177 · 2003-12-30 · by dgoodman
Problem Statement
We refer to the positions in our sequence starting with 1. Let the items in our sequence
initially be 1, 2, ..., n. Let k be the specified final position, and
let remove be a list of
Create a class Removal that contains a method finalPos that takes as input n,
the original sequence length, k the final position of interest,
and remove, a
Constraints
- n will be between 1 and 2,000,000,000 inclusive.
- k will be between 1 and n inclusive.
- remove will contain between 1 and 50 elements inclusive.
- Each element of remove will be formatted as "lo-hi".
- In each element of remove, neither lo nor hi will have leading zeros.
- In each element of remove, 0 < lo <= hi <= n.
- In each element of remove, hi will be less than or equal to the number of items remaining after the preceding removals.
8
3
{"3-4","4-5"}
Returns: 5
As described above, the final sequence will be 1, 2, 5, 8, so item 5 ends up in position 3 of the final sequence.
100
13
{"19-50","19-50","19-19"}
Returns: 13
None of these removals affects position 13.
100
39
{"19-50","19-50","19-19"}
Returns: -1
The final sequence contains less than 39 items.
2000000000
2000000000
{"1-1"}
Returns: -1
2000000000
1999999999
{"1-1"}
Returns: 2000000000
Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Removal with a public method int finalPos(int n, int k, vector<string> remove) · 62 test cases · 2 s / 256 MB per case