1 条题解
-
4
#include <bits/stdc++.h> using namespace std; #define int long long void solve() { int n,C; cin >> n >> C; priority_queue<int> pq; // 优先队列 pq,用于优先处理人数多的余数 int ans = 0; // 记录总考场数 string name; int num; for(int i = 1; i <= n; i++){ cin >> name >> num; // 计算该学校需要的监考人数(向上取整)并输出 cout << name << " " << (num + C - 1) / C << '\n'; // ans累加整除部分的考场数 ans += num/C; if(num%C != 0) pq.push(num%C); // 余数入 队列,后续处理 } int a[100000]; // 记录各考场已占用的人数,用于判断空位 int id = 0; // 下标 while(!pq.empty()){ int op = pq.top(); pq.pop(); // 取出当前最大的余数 bool ok = false; for(int i = 1; i <= id; i++){ if(op <= C - a[i]){ // 若当前考场空位能容纳该余数 a[i] += op; // 占用空位 ok = true; break; } } if(!ok) { // 无法容纳,新增考场 a[++id] = op; ans++; } } cout << ans << '\n'; } signed main() { ios::sync_with_stdio(0); cin.tie(0),cout.tie(0); int T = 1; while (T--) solve(); return 0; }
信息
- ID
- 1195
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 6
- 标签
- 递交数
- 54
- 已通过
- 18
- 上传者