2 条题解
-
0

#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N=25; struct node{LL v; int b;} a[N]; bool cmp(node n1, node n2){ return n1.v > n2.v; } int main(){ int n; LL C; scanf("%d%lld", &n, &C); for(int i=1; i<=n; i++) scanf("%lld%d", &a[i].v, &a[i].b); sort(a+1, a+n+1, cmp); int t=1; LL ans=0; while(a[t].v >= C) ans += a[t++].b; while(1){ LL sum = C; for(int i=t; i<=n; i++){ while(sum >= a[i].v && a[i].b > 0 && ) {sum -= a[i].v; a[i].b--;} } if(sum > 0){ for(int i=n; i>=t; i--) if(a[i].b > 0){ sum -= a[i].v; a[i].b--; break; } } if(sum <= 0) ans++; else break; } printf("%lld\n", ans); return 0; } -
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=25; struct node{LL v; int b;} a[N]; bool cmp(node n1, node n2){ return n1.v>n2.v; } int main(){ int n; LL C; scanf("%d%lld", &n, &C); for(int i=1; i<=n; i++) scanf("%lld%d", &a[i].v, &a[i].b); sort(a+1, a+n+1, cmp); int t=1; LL ans=0; while(a[t].v>=C) ans+=a[t++].b; while(1){ LL sum=C; for(int i=t; i<=n; i++){ while(sum>=a[i].v && a[i].b>0 && ) {sum-=a[i].v; a[i].b--;} } if(sum>0){ for(int i=n; i>=t; i--) if(a[i].b>0){ sum-=a[i].v; a[i].b--; break; } } if(sum<=0) ans++; else break; } printf("%lld\n", ans); return 0; }
- 1
信息
- ID
- 3340
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 6
- 标签
- 递交数
- 73
- 已通过
- 24
- 上传者