1 条题解
-
0
C :
#include<stdio.h> #include<stdlib.h> int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } main() { int nums[1000], max, n; while(scanf("%d", &max) != EOF) { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &nums[i]); qsort(nums, n, sizeof(int), cmp); int count = 0, total = 0; for(int i = 0; i < n; i++) { if((total += nums[i]) <= max) count++; else break; } printf("%d\n", count); } }
C++ :
#include<iostream> #include<algorithm> using namespace std; int main(){ int w; int N[10000]; int n; while(scanf("%d",&w) != EOF){ cin>>n; for(int i = 0;i < n;i++){ cin>>N[i]; } sort(N,N+n); int t = 0; for(int i = 0;i < n;i++){ w -= N[i]; if(w >= 0){ t++; } if(w < 0){ break; } } cout<<t<<endl; } }
- 1
信息
- ID
- 1134
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者