Description
Input
Output
Sample Input
Sample Output
HintHint
请用VC/VC++提交
大意: 注意范围,加一个正数进去。
#include<cstring> #include<cstdio> using namespace std; const int MAX = 1000015; const int N = 510000; int w[MAX],a[MAX],p[MAX]; void sort(int *a,int n,int mx) { for(int i =1 ; i<= mx;i++) w[i] =0; for(int i = 1; i <= n;i++) w[a[i]]++; for(int i =1; i <= mx;i++) w[i] += w[i-1]; for(int i = n; i >= 1; i--){ p[w[a[i]]] = a[i]; w[a[i]]--; } } int main() { int n,m; scanf("%d%d",&n,&m); for(int i = 1; i <= n; i++){ scanf("%d",&a[i]); a[i] += N; } sort(a,n,MAX); for(int i = n ; i >= n-m+1 ;i--) printf("%d ",p[i]-N); return 0; }
原文:http://www.cnblogs.com/zero-begin/p/4369612.html