Codeforces-609A USB Flash Drives

mac2024-08-18  61

Codeforces-609A USB Flash Drives

题目链接:Codeforces-609A 题目大意:给定一个盘 盘区分大小 问你存下一个给定大小的文件,最少需要多少分区

解题思路:排序从小到大

代码块:

#include<iostream> #include<algorithm> using namespace std; int arrA[1005] = {0}; int cmp(int o1, int o2){ return o1 > o2; } int main(){ int n, nSize; cin>>n>>nSize; for(int i = 0; i < n; i++){ cin>>arrA[i]; } sort(arrA, arrA + n, cmp); int sum = 0, res = 0; for(int i = 0; i < n; i++){ sum += arrA[i]; res++; if(sum >= nSize) break; } cout<<res; return 0; }
最新回复(0)