挺水的是吧?
是啊,挺水的.
挺水的比赛怎么没过?
宝宝心里苦啊,当时光顾着看n的范围了,没看清数的范围也不过5000,T T,好崩溃啊T T
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int res[100010],a[3010],End[1010]; int main() { int n,m; while(~scanf("%d%d",&n,&m)) { for(int i = 0;i < n;i++) scanf("%d",&a[i]); sort(a,a + n); memset(res,0,sizeof(res)); int max = 0,all = m; for(int j = n-1;j > 0;j--) { for(int i = j-1;i >= 0;i--) { int num = a[i] + a[j]; res[num]++; if(num > max) max = num; } } int tot = 0; for(int i = max;i >= 0;i--) { if(res[i] != 0 && res[i] <= all) { while(res[i]) { End[tot++] = i; res[i]--; } all -= res[i]; } else if(res[i] != 0 && res[i] > all) { while(res[i]) { End[tot++] = i; res[i]--; } break; } } for(int i = 0;i < m;i++) { if(i == 0)printf("%d",End[i]); else printf(" %d",End[i]); } printf("\n"); } return 0; }
时间: 2024-10-15 15:40:14