6 solutions
-
0
这题需要注意的是当养了一只僵尸后,这只僵尸就要一直被养下去,他需要的消耗是从他来的那天开始一直到不养他的那天,为提高收养量,需将收养成本降到最小,即在有限成本条件下,将消耗排序
#include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int N=1e3+10; int a[N]; int main(){ int n,sum,ans=0; cin>>n>>sum; for(int i=1;i<=n;i++) { cin>>a[i]; a[i]*=(n-i+1); } sort(a+1,a+n+1); while(ans<n){ sum-=a[ans+1]; if(sum<0) break; ans++; } printf("%d",ans); return 0; }
Information
- ID
- 25
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 283
- Accepted
- 64
- Uploaded By