3 条题解
-
0
#include<bits/stdc++.h> using namespace std; int w,n; int p[30005]; int ans; signed main(){ ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); cin>>w>>n; for(int i=1;i<=n;i++) cin>>p[i]; sort(p+1,p+n+1); int l=1,r=n; while(l<=r){//双指针 if(p[l]+p[r]>w){//1. r--;//p[r]单独分一组 ans++; } else{//2. l++;r--; ans++;//一起分一组 } } cout<<ans; return 0; }
- 1
信息
- ID
- 227
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 4
- 标签
- (无)
- 递交数
- 249
- 已通过
- 124
- 上传者