社区讨论
求条,WA on #4
P12938[NERC 2019] Elections参与者 3已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mhz4ibvy
- 此快照首次捕获于
- 2025/11/15 01:19 3 个月前
- 此快照最后确认于
- 2025/11/16 14:01 3 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
int a[105][105], sum[105];
vector<int> ans;
struct node {
int x, y;
bool operator<(const node& t)const {
return x > t.x;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int j = 1; j <= n; j++) {
for (int i = 1; i <= m; i++) {
sum[j] += a[i][j];
}
}
int maxn = 0;
for (int j = 1; j < n; j++) {
maxn = max(maxn, sum[j]);
}
if (sum[n] <= maxn) {
cout << 0;
return 0;
} else {
int cnt = 0;
for (int i = 1; i <= m; i++) {
int maxx = 0;
for (int j = 1; j < n; j++) {
maxx = max(maxx, a[i][j]);
}
if (a[i][n] > maxx)cnt++;
}
if (cnt == m) {
cout << m << '\n';
for (int i = 1; i <= m; i++) {
cout << i << ' ';
}
return 0;
} else {
vector<node> vec;
for (int i = 1; i <= m; i++) {
int maxx = 0;
for (int j = 1; j < n; j++) {
maxx = max(maxx, a[i][j]);
}
if (a[i][n] > maxx) {
vec.push_back({a[i][n] - maxx, i});
}
}
sort(vec.begin(), vec.end());
for (auto it : vec) {
ans.push_back(it.y);
for (int j = 1; j <= n; j++) {
sum[j] -= a[it.y][j];
}
int maxx = 0;
for (int j = 1; j < n; j++) {
maxx = max(maxx, sum[j]);
}
if (sum[n] <= maxx)goto mw;
}
}
}
mw:
cout << ans.size() << '\n';
for (auto it : ans) {
cout << it << ' ';
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...