#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define low(x) x&(-x)
using namespace std;
const ll inf = 1e16;
int n, m;
struct node { int x; ll y; }a[3005];
int c[3005], b[3005];
ll ans, sum;
bool cmp(node a, node b) {
return a.y>b.y;
}
int main() {
scanf("%d%d", &n, &m);
rep(i, 1, n) {
scanf("%d%lld", &a[i].x, &a[i].y);
}
sort(a + 1, a + 1 + n, cmp);
ans = inf;
rep(i, 1, n) {
rep(j, 1, m) c[j] = 0; sum = 0;
rep(j, 1, n) b[j] = 0;
rep(j, 1, n) {
if (a[j].x == 1) c[a[j].x]++;
else {
if (c[a[j].x] + 1 >= i) sum += a[j].y, c[1]++, b[j] = 1;
else c[a[j].x]++;
}
}
for (int j = n; j >= 1; j--)
if (a[j].x != 1 && b[j] == 0 && c[1]<i) b[j] = 1, sum += a[j].y, c[1]++;
if (c[1] >= i) ans = min(ans, sum);
}
cout << ans << endl;
return 0;
}
codeforces1020C. Elections
猜你喜欢
转载自blog.csdn.net/qq_37765455/article/details/81603730
今日推荐
周排行