题面
来源: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
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
3/3
解出的采样 ↑
- 100采样 1 · 解出
- 100采样 2 · 解出
- 100采样 3 · 解出
- 2.0k平均输出 token(含思考) ↓
- 218.4输出速度 tokens/s ↑
- 11 秒延迟 ↓
- 0.91×CPU 时间 / 官方解 ↓
- 同阶 3时间复杂度(相对官方解)
MiniMax M3.1 FlashMiniMax
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 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。
代码
#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; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; struct Job { int64 deadline; int64 duration; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<Job> jobs(N); for (int i = 0; i < N; ++i) { int64 s, t; cin >> s >> t; // Starting by s is equivalent to finishing by s + t. jobs[i] = {s + t, t}; } sort(jobs.begin(), jobs.end(), [](const Job& a, const Job& b) { return a.deadline < b.deadline; }); priority_queue<int64> selected; int64 elapsed = 0; for (const Job& job : jobs) { elapsed += job.duration; selected.push(job.duration); if (elapsed > job.deadline) { elapsed -= selected.top(); selected.pop(); } } cout << selected.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = long long; struct Job { int64 deadline; int64 duration; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<Job> jobs(N); for (auto &job : jobs) { int64 s, t; cin >> s >> t; job.deadline = s + t; job.duration = t; } sort(jobs.begin(), jobs.end(), [](const Job &a, const Job &b) { return a.deadline < b.deadline; }); priority_queue<int64> durations; int64 elapsed = 0; for (const auto &job : jobs) { elapsed += job.duration; durations.push(job.duration); if (elapsed > job.deadline) { elapsed -= durations.top(); durations.pop(); } } cout << durations.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<pair<long long, long long>> jobs; jobs.reserve(N); for (int i = 0; i < N; i++) { long long s, t; cin >> s >> t; long long deadline = s + t; jobs.push_back({deadline, t}); } sort(jobs.begin(), jobs.end()); priority_queue<long long> pq; __int128 currentTime = 0; for (auto [deadline, duration] : jobs) { pq.push(duration); currentTime += duration; if (currentTime > deadline) { currentTime -= pq.top(); pq.pop(); } } cout << pq.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<pair<long long, long long>> jobs; jobs.reserve(N); for (int i = 0; i < N; i++) { long long s, t; cin >> s >> t; jobs.push_back({s + t, t}); } sort(jobs.begin(), jobs.end()); priority_queue<long long> chosen; __int128 totalTime = 0; for (auto [deadline, duration] : jobs) { totalTime += duration; chosen.push(duration); if (totalTime > (__int128)deadline) { totalTime -= chosen.top(); chosen.pop(); } } cout << chosen.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<pair<long long, long long>> jobs; jobs.reserve(N); for (int i = 0; i < N; ++i) { long long s, t; cin >> s >> t; long long deadline = s + t; jobs.push_back({deadline, t}); } sort(jobs.begin(), jobs.end()); priority_queue<long long> pq; __int128 total = 0; for (auto [deadline, duration] : jobs) { total += duration; pq.push(duration); if (total > (__int128)deadline) { total -= pq.top(); pq.pop(); } } cout << pq.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; struct Job { long long deadline; long long duration; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<Job> jobs; jobs.reserve(N); for (int i = 0; i < N; ++i) { long long s, t; cin >> s >> t; // Starting by time s is equivalent to finishing by s + t. jobs.push_back({s + t, t}); } sort(jobs.begin(), jobs.end(), [](const Job& a, const Job& b) { return a.deadline < b.deadline; }); priority_queue<long long> chosen; __int128 totalTime = 0; for (const Job& job : jobs) { chosen.push(job.duration); totalTime += job.duration; if (totalTime > job.deadline) { // Discard the longest job to minimize the total workload. totalTime -= chosen.top(); chosen.pop(); } } cout << chosen.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; // (completion deadline, processing time) vector<pair<long long, long long>> jobs; jobs.reserve(N); for (int i = 0; i < N; ++i) { long long s, t; cin >> s >> t; jobs.emplace_back(s + t, t); } sort(jobs.begin(), jobs.end()); priority_queue<long long> selected; __int128 total = 0; for (const auto& [deadline, duration] : jobs) { selected.push(duration); total += duration; if (total > static_cast<__int128>(deadline)) { total -= selected.top(); selected.pop(); } } cout << selected.size() << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; struct Job { long long deadline; long long duration; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while (T--) { int N; cin >> N; vector<Job> jobs; jobs.reserve(N); for (int i = 0; i < N; ++i) { long long s, t; cin >> s >> t; jobs.push_back({s + t, t}); } sort(jobs.begin(), jobs.end(), [](const Job& a, const Job& b) { return a.deadline < b.deadline; }); priority_queue<long long> selected; __int128 elapsed = 0; for (const Job& job : jobs) { selected.push(job.duration); elapsed += job.duration; if (elapsed > static_cast<__int128>(job.deadline)) { elapsed -= selected.top(); selected.pop(); } } cout << selected.size() << '\n'; } return 0; }