题目 › usaco-1451

Job Completion

USACO 2024 December · 金组 · 2024-12 · L3 困难 · C++17 · 时限 2 秒 · 测试点等分

查看原题跳到结果

题面

来源:USACO 官网。模型收到的是同一份题面的文字。

Bessie the cow has $N$ ($1\le N\le 2\cdot 10^5$) jobs for you to potentially complete. The $i$-th one, if you choose to complete it, must be started at or before time $s_i$ and takes $t_i$ time to complete ($0\le s_i\le 10^{18}, 1\le t_i\le 10^{18}$).

What is the maximum number of jobs you can complete? Time starts at $0$, and once you start a job you must work on it until it is complete, without starting any other jobs in the meantime.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains $T$, the number of independent test cases ($1\le T\le 10$). Each test case is formatted as follows.

The first line contains $N$.

Each of the next $N$ lines contains two integers $s_i$ and $t_i$. Row $i+1$ has the details for the $i$th job.

It is guaranteed that the sum of $N$ over all test cases does not exceed $3\cdot 10^5$.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, the maximum number of jobs you can complete, on a new line.

SAMPLE INPUT:

3
2
1 4
1 2
2
2 3
1 2
3
1 4
2 3
1 2

SAMPLE OUTPUT:

1
2
2

For the first test case, you can only complete one of the jobs. After completing one job, it will then be time $2$ or later, so it is too late to start the other job, which must be started at time $1$ or earlier.

For the second test case, you can start the second job at time $0$ and finish at time $2$, then start the first job at time $2$ and finish at time $5$.

SCORING:

  • Inputs 2: Within the same test case, all $t_i$ are equal.
  • Inputs 3-4: $N\le 2000$, $s_i, t_i\le 2000$
  • Inputs 5-8: $N\le 2000$
  • Inputs 9-16: No additional constraints.

Problem credits: Benjamin Qi

结果

Kimi K3.1 ProKimi

auto(max)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 6.6k平均输出 token(含思考) ↓
  • 24.3输出速度 tokens/s ↑
  • 173 秒延迟 ↓
  • 0.95×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 2.0k平均输出 token(含思考) ↓
  • 218.4输出速度 tokens/s ↑
  • 11 秒延迟 ↓
  • 0.91×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

MiniMax M3.1 FlashMiniMax

auto(max)

3/3

解出的采样 ↑

  • 100采样 1 · 解出
  • 100采样 2 · 解出
  • 100采样 3 · 解出
  • 9.8k平均输出 token(含思考) ↓
  • 152.7输出速度 tokens/s ↑
  • 79 秒延迟 ↓
  • 0.97×CPU 时间 / 官方解 ↓
  • 同阶 3时间复杂度(相对官方解)

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 49 行
#include <bits/stdc++.h>
using namespace std;

using int64 = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T;
    cin >> T;

    while (T--) {
        int N;
        cin >> N;

        vector<pair<int64, int64>> jobs;
        jobs.reserve(N);

        for (int i = 0; i < N; ++i) {
            int64 s, t;
            cin >> s >> t;
            // Starting by s is equivalent to completing by s + t.
            jobs.push_back({s + t, t});
        }

        sort(jobs.begin(), jobs.end(),
             [](const auto& a, const auto& b) {
                 return a.first < b.first;
             });

        priority_queue<int64> durations;
        int64 elapsed = 0;

        for (const auto& [deadline, duration] : jobs) {
            elapsed += duration;
            durations.push(duration);

            while (elapsed > deadline) {
                elapsed -= durations.top();
                durations.pop();
            }
        }

        cout << durations.size() << '\n';
    }

    return 0;
}