暴力贪心就能过,我还以为要优化呢…… view code 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 #define N 10010 9 struct data 10 { 11 int d, v; 12 }a[N]; 13 bool f[N]; 14 int cmp(data a, data b) 15 { 16 return a.v > b.v; 17 } 18 int main() 19 { 20 int n, i, mv; 21 while (scanf("%d", &n) != EOF) 22 { 23 mv = 0; 24 memset(f, 0, sizeof(f)); 25 for (i = 0; i < n; i++) 26 scanf("%d%d", &a[i].v, &a[i].d); 27 sort(a, a + n, cmp); 28 for (i = 0; i < n; i++) 29 { 30 int t = a[i].d; 31 while (t > 0 && f[t]) t--; 32 if (t > 0) 33 { 34 f[t] = 1; 35 mv += a[i].v; 36 } 37 } 38 printf("%d\n", mv); 39 } 40 return 0; 41
|