#P15843. [Bulgarian NOI 2024] 显卡 / GPUs
[Bulgarian NOI 2024] 显卡 / GPUs
Background
When submitting this problem on Luogu, please choose a language standard of >= C++17. You do not need to include #include "gpus.h". Instead, explicitly place the following at the beginning of your code:
#include <algorithm>
#include <iostream>
#include <vector>
inline std::ostream& operator<<(std::ostream& out, __int128 num)
{
bool flip = false;
if (num < 0)
{
flip = true;
num = -num;
}
std::string str = "";
do
{
str += '0' + num % 10;
num /= 10;
}
while (num > 0);
std::reverse(str.begin(), str.end());
if (flip) str = "-" + str;
out << str;
return out;
}
__int128 solveGpus(std::vector<int>& gpuCosts, std::vector<int>& reqTimes);
Problem Description
As the founder of a modern startup company, you have launched a generative AI project. The generation process for images, text, etc. is split into tasks, and each task needs exactly one GPU (graphics card) to run for one second. You know in advance when each task becomes available—task becomes executable at second . You can use an external supercomputer with GPUs, but the cost of using each GPU is different: GPU costs per second. You need to assign each task to a specific GPU and a specific time, such that the time is not earlier than , and no other task is scheduled on the same GPU at the same moment. In other words, each GPU can process at most one task in any given second.
Let the final completion time be (i.e., the latest scheduled time among all tasks plus one), and the total payment be . If task is assigned to GPU , then . Your goal is to find the minimum possible value of . You need to solve independent instances of this problem.
Interaction Details
This is an interactive problem. You do not need to read data from standard input or write data to standard output. You only need to implement a function named solveGpus, defined as follows:
__int128 solveGpus(
std::vector<int>& gpuCosts,
std::vector<int>& reqTimes
);
This function takes two vectors as parameters, and both vectors are sorted in non-decreasing order. You may modify the passed-in vectors. The return type is __int128, which represents a 128-bit integer—this is necessary because the answer may exceed the range of long long. This function will be called multiple times, and each call corresponds to an independent problem instance.
Your code should not contain a main function, but it may contain any other helper functions, classes, variables, etc. Your code must include the header file gpus.h, which, for convenience, already defines the operator used to output values of type __int128. Please include this header via the following preprocessor directive:
#include "gpus.h"
Your code will be compiled together with the grader, which is responsible for reading input and writing output. In the judging system, the only time counted toward the time limit is the time your code actually spends executing; the time for input/output operations is not counted in the total time.
For local testing, we provide a local grader Lgrader.cpp and a copy of the header file gpus.h. You need to compile your code together with the local grader for testing. You can place them in the same directory and use the following command:
g++ -O2 -std=c++17 -Wl,--stack,1073741824 -Wall gpus.cpp Lgrader.cpp -o gpus.exe
Input Format
The input format of the local grader is as follows:
First comes , then for each test case: , followed by all and all .
1
8 4
1 2 2 6
0 0 0 0 1 2 2 2
39
Hint
Subtasks
| Subtask | Score | ||
|---|---|---|---|
You will receive the score for a subtask only if you successfully pass all test points corresponding to that subtask.
Constraints
Translation completed by Qwen3.5-397B-A17B.
Translated by ChatGPT 5