Download code/train/C++/0008009_FoxAndDoraemon.cpp from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/train/C%2B%2B/0008009_FoxAndDoraemon.cpp
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/code/train/C++/0008009_FoxAndDoraemon.cpp
-
curl -L -o 0008009_FoxAndDoraemon.cpp https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/code/train/C%2B%2B/0008009_FoxAndDoraemon.cpp
1.19 kB
| using namespace std; | |
| vector<int> W; | |
| int C; | |
| bool can(int T) { | |
| long long foxes = 1; | |
| int cur = 0; | |
| for (int i=0; i<(int)W.size(); ++i) { | |
| if (foxes==0 || cur+W[i]>T) { | |
| return false; | |
| } | |
| int nsplits = (T-cur-W[i])/C; | |
| while (i+foxes<(int)W.size() && nsplits--) { | |
| foxes <<= 1; | |
| cur += C; | |
| } | |
| assert(cur + W[i] <= T); | |
| --foxes; | |
| } | |
| return true; | |
| } | |
| class FoxAndDoraemon { | |
| public: | |
| int minTime(vector <int> workCost, int splitCost) { | |
| W = workCost; | |
| sort(W.begin(), W.end(), greater<int>()); | |
| C = splitCost; | |
| int lo = 1; | |
| int hi = 2; | |
| while (!can(hi)) { | |
| lo = hi + 1; | |
| hi <<= 1; | |
| } | |
| while (lo < hi) { | |
| int mid = lo + (hi-lo)/2; | |
| if (can(mid)) { | |
| hi = mid; | |
| } else { | |
| lo = mid + 1; | |
| } | |
| } | |
| return lo; | |
| } | |
| }; | |