| shots = """ | |
| # Kth Largest Element in an Array | |
| ## Problem Description | |
| You are given an integer array weights of length n, and an integer k (1 ≤ k ≤ n). Your task is to determine the kth largest element in the array. | |
| The kth largest element is defined as the element that appears in the k-th position after sorting the array in non-increasing (descending) order. In other words, if you sort the array from largest to smallest, the element at the k-th position in this sorted array is the answer. | |
| Note: | |
| This is not the k-th distinct element; if the array contains duplicate values, each occurrence is considered in the sorting. | |
| For example, if weights = [5, 1, 5, 3] and k = 2, then after sorting in descending order we get [5, 5, 3, 1], and the second largest element is 5 (the second occurrence of 5). | |
| ## Input Format | |
| The first line contains two integers n and k, separated by a space. | |
| n is the number of elements in the array, and k is the position (1-based) of the element you need to find in the descending sorted array. | |
| The second line contains n space-separated integers, representing the elements of the weights array. | |
| ## Output Format | |
| Output a single integer: the value of the k-th largest element in the given array. | |
| ## Sample Input 1: | |
| 6 2 | |
| 3 2 1 5 6 4 | |
| Sample Output 1: | |
| 5 | |
| Explanation: | |
| The input array weights has 6 elements: [3, 2, 1, 5, 6, 4]. | |
| We are asked to find the 2nd largest element (k = 2). | |
| After sorting the array in descending order, we get [6, 5, 4, 3, 2, 1]. | |
| The 2nd element in this sorted array is 5, so the output is 5. | |
| ## Constraints and Notes | |
| 1 ≤ n ≤ 100,000 | |
| 1 ≤ k ≤ n | |
| Each element in the weights array is an integer and may be positive, negative, or zero. | |
| That is, for all valid i: −10⁹ ≤ weights[i] ≤ 10⁹. | |
| The array may contain duplicate values (each duplicate is treated as a separate entry when determining the k-th largest element). | |
| """ | |
| Original_prompt = """ | |
| You are an expert python competitive programmar and your goal is to construct input-generators for testing programming contest problems. | |
| You will write relevant generators and finally construct 'construct_inputs' function that returns a list of diverse inputs sampled from the generator. | |
| Remember to strictly follow the instructions and constraints present in the problem statement | |
| """ | |
| random_input_prompt = """ | |
| You are an expert python competitive programmar and your goal is to construct input-generators for testing programming contest problems. | |
| You will write relevant generators and finally construct 'construct_inputs' function that returns a list of diverse inputs sampled from the generator. | |
| Each string in the list should be formatted as standard input and ready for use in the contest problem. | |
| Remember to strictly follow the instructions and constraints present in the problem statement | |
| The input and output will follow the format below: | |
| Input | |
| <USER> | |
| Contains the description of an algorithm problem | |
| and the instruction to generate the corresponding function | |
| </USER> | |
| Output | |
| <ASSISTANT> | |
| Only include the generated code (no explanation or additional text) | |
| </ASSISTANT> | |
| Example: | |
| <USER> | |
| {EXAMPLE_PROBLEM} | |
| Construct a random input generator. | |
| </USER> | |
| <ASSISTANT> | |
| import numpy as np | |
| def random_input_generator(weight_min, weight_max, size_min, size_max): | |
| # Generate random size for the array | |
| weights_size = np.random.randint(size_min, size_max+1) | |
| # Generate random weights and format as a space-separated string | |
| weights = ' '.join(str(np.random.randint(weight_min, weight_max)) for _ in range(weights_size)) | |
| # Randomly select a k value within the range of the size of the array | |
| k = np.random.randint(1, weights_size + 1) | |
| # Return the formatted string for weights and k | |
| return f"{weights_size} {k}\n{weights}" | |
| def construct_inputs(): | |
| inputs_list = [] | |
| # Small inputs (weights between 1 and 1000, array size between 1 and 10) | |
| for i in range(15): | |
| inputs_list.append(random_input_generator(1, 10**3, 1, 10)) | |
| # Medium inputs (weights between 1 and 10^6, array size between 1 and 1000) | |
| for i in range(15): | |
| inputs_list.append(random_input_generator(1, 10**6, 1, 10**3)) | |
| # Large inputs (weights between 1 and 10^9, array size between 1 and 100000) | |
| for i in range(15): | |
| inputs_list.append(random_input_generator(1, 10**9, 1, 10**5)) | |
| return inputs_list | |
| </ASSISTANT> | |
| """ | |
| random_input_template = """ | |
| <USER> | |
| {PROBLEM} | |
| Construct a random input generator. | |
| Use the format used in the above example by returning a single function that builds diverse inputs named 'construct_inputs' | |
| </USER> | |
| """ | |
| ad_origin = """ | |
| You are an expert python competitive programmar and your goal is to construct input-generators for testing programming contest problems. | |
| You will write relevant generators and finally construct 'construct_inputs' function that returns a list of diverse inputs sampled from the generator. | |
| Remember to strictly follow the instructions and constraints present in the problem statement | |
| """ | |
| adversarial_prompt = """ | |
| You are an expert python competitive programmar and your goal is to construct input-generators for testing programming contest problems. | |
| You will write relevant generators and finally construct 'construct_inputs' function that returns a list of diverse inputs sampled from the generator. | |
| Each string in the list should be formatted as standard input and ready for use in the contest problem. | |
| Remember to strictly follow the instructions and constraints present in the problem statement | |
| The input and output will follow the format below: | |
| Input | |
| <USER> | |
| Contains the description of an algorithm problem | |
| and the instruction to generate the corresponding function | |
| </USER> | |
| Output | |
| <ASSISTANT> | |
| Only include the generated code (no explanation or additional text) | |
| </ASSISTANT> | |
| <USER> | |
| {EXAMPLE_PROBLEM} | |
| Construct an adversarial input generator. | |
| </USER> | |
| <ASSISTANT> | |
| import numpy as np | |
| ## case 1 - alternating large and small weights | |
| def generate_adversarial_inputs_1(weight_size, max_weight, k): | |
| # Alternating large and small weights | |
| weights = ' '.join(str(1 if i % 2 == 0 else max_weight) for i in range(weight_size)) | |
| return f"{weight_size} {k}\n{weights}" | |
| ## case 2 - equal_weights | |
| def adversarial_input_generator_2(weight_size, max_weight, k): | |
| # All weights are the same | |
| weights = ' '.join(str(max_weight) for _ in range(weight_size)) | |
| return f"{weight_size} {k}\n{weights}" | |
| # Case 3 - Large weights at the ends | |
| def adversarial_input_generator_3(weight_size, max_weight, k): | |
| # Large weights at the ends of the array | |
| weights = [max_weight] + ['1' for _ in range(weight_size - 2)] + [max_weight] | |
| weights = ' '.join(str(w) for w in weights) | |
| return f"{weight_size} {k}\n{weights}" | |
| def construct_inputs(): | |
| inputs_list = [] | |
| weight_sizes = [10, 1000, 100000] | |
| max_weights = [10**3, 10**6, 10**9] | |
| for weight_size in weight_sizes: | |
| for max_weight in max_weights: | |
| ks = [1, 2, 5, weight_size // 2, weight_size - 1, weight_size] | |
| for k in ks: | |
| # Adding adversarial input cases | |
| inputs_list.append(generate_adversarial_inputs_1(weight_size, max_weight, k)) | |
| inputs_list.append(adversarial_input_generator_2(weight_size, max_weight, k)) | |
| inputs_list.append(adversarial_input_generator_3(weight_size, max_weight, k)) | |
| return inputs_list | |
| </ASSISTANT> | |
| """ | |
| adversarial_input_template = """ | |
| <USER> | |
| {PROBLEM} | |
| Construct an adversarial input generator. | |
| Use the format used in the above example by returning a single function that builds diverse inputs named 'construct_inputs' | |
| </USER> | |
| """ |
Xet Storage Details
- Size:
- 7.69 kB
- Xet hash:
- cfa8fb82d6e9a150c17dd6cc32953160e0c7c121f1538e00c5b16c01c6d2cd15
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.