Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
请大牛们指教一下为什么会 wa????#include <iostream> #include <stdlib.h> using namespace std; int cmp ( const void *a , const void *b ) { return *(int *)a - *(int *)b; } int main() { int t, a[100000]; int i, count; long int n, s, sum; scanf("%d", &t); while (t--) { count = 0; sum = 0; scanf("%ld %ld", &n, &s); for (i =0; i < n; i++ ) scanf("%d", &a[i]); qsort(a, n, sizeof(a[0]), cmp); for (i = n-1; i >= 0; i--) { sum += a[i]; count ++; if(sum >= s) { printf("%d\n", count); break; } } if (s > sum) printf("%d\n", 0); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator