Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
Download leetcode/lc1561/code.rs from Gax-c/VeriContest_Lite: direct link, hf CLI and curl.
- Browser
- Download file 1.61 kB
-
https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1561/code.rs
- Command line
-
hf download hf://datasets/Gax-c/VeriContest_Lite/leetcode/lc1561/code.rs
-
curl -L -o code.rs https://huggingface.co/datasets/Gax-c/VeriContest_Lite/resolve/main/leetcode/lc1561/code.rs
1.61 kB
| impl Solution { | |
| fn ms_merge(a: &Vec<i32>, b: &Vec<i32>) -> Vec<i32> { | |
| let mut result: Vec<i32> = Vec::new(); | |
| let mut i: usize = 0; | |
| let mut j: usize = 0; | |
| while i < a.len() || j < b.len() | |
| { | |
| if i < a.len() && (j >= b.len() || a[i] <= b[j]) { | |
| result.push(a[i]); | |
| i = i + 1; | |
| } else { | |
| result.push(b[j]); | |
| j = j + 1; | |
| } | |
| } | |
| result | |
| } | |
| fn ms_sort(nums: &Vec<i32>) -> Vec<i32> { | |
| let n = nums.len(); | |
| if n <= 1 { | |
| let mut result = Vec::new(); | |
| if n == 1 { | |
| result.push(nums[0]); | |
| } | |
| return result; | |
| } | |
| let mid = n / 2; | |
| let mut left: Vec<i32> = Vec::new(); | |
| let mut i: usize = 0; | |
| while i < mid | |
| { | |
| left.push(nums[i]); | |
| i = i + 1; | |
| } | |
| let mut right: Vec<i32> = Vec::new(); | |
| let mut j: usize = mid; | |
| while j < n | |
| { | |
| right.push(nums[j]); | |
| j = j + 1; | |
| } | |
| let sorted_left = Self::ms_sort(&left); | |
| let sorted_right = Self::ms_sort(&right); | |
| let result = Self::ms_merge(&sorted_left, &sorted_right); | |
| result | |
| } | |
| pub fn max_coins(piles: Vec<i32>) -> i32 { | |
| let sorted = Self::ms_sort(&piles); | |
| let n = sorted.len(); | |
| let mut sum: i32 = 0; | |
| let third = n / 3; | |
| let mut k = third; | |
| while k < n { | |
| sum = sum + sorted[k]; | |
| k = k + 2; | |
| } | |
| sum | |
| } | |
| } | |