#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 NN 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 ii becomes executable at second TiT_i. You can use an external supercomputer with MM GPUs, but the cost of using each GPU is different: GPU jj costs CjC_j per second. You need to assign each task ii to a specific GPU jj and a specific time, such that the time is not earlier than TiT_i, 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 FF (i.e., the latest scheduled time among all tasks plus one), and the total payment be SS. If task ii is assigned to GPU GiG_i, then S=CG1+CG2+⋯+CGNS = C_{G_1} + C_{G_2} + \dots + C_{G_N}. Your goal is to find the minimum possible value of F×SF \times S. You need to solve QQ 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 QQ, then for each test case: N,MN, M, followed by all CjC_j and all TiT_i.

1
8 4
1 2 2 6
0 0 0 0 1 2 2 2
39

Hint

Subtasks

Subtask Score N≤N \le Q≤Q \le
11 1010 11
22 88 800800 22
33 1313 22002200
44 1414 10410^4
55 1111 10510^5
66 1515 10610^6 55
77 2929 10710^7

You will receive the score for a subtask only if you successfully pass all test points corresponding to that subtask.

Constraints

  • 1≤N≤1071 \le N \le 10^7
  • 1≤M≤N1 \le M \le N
  • 0≤Ti≤N0 \le T_i \le N
  • 1≤Ci≤2N1 \le C_i \le 2N
  • 1≤Q≤51 \le Q \le 5

Translation completed by Qwen3.5-397B-A17B.

Translated by ChatGPT 5