社区讨论
90pts WA on #15,#20
P14635[NOIP2025] 糖果店参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @mipst70h
- 此快照首次捕获于
- 2025/12/03 17:22 3 个月前
- 此快照最后确认于
- 2025/12/05 18:00 3 个月前
考场上写的
当时一直测不过candy6,现在错了这两个点,蒟蒻求调
注释和垃圾代码没去请谅解
CPP#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
ll n,m,mins=1e18+1,maxy=0,ans,now;
struct candy{
ll x,y;
bool f=0;
}can[100009];
bool cmp(candy a,candy b){
return a.x<b.x;
}
bool cmp1(candy a,candy b){
return a.x+a.y<b.x+b.y;
}
bool cmp2(candy a,candy b){
return a.y<b.y;
}
int main(){
std::ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>can[i].x>>can[i].y;
mins=min(mins,can[i].x+can[i].y);
}
//cout<<">>>>>S1<<<<<"<<endl;
//cout<<"mins:"<<mins<<endl;
sort(can,can+n,cmp);
int i=0;
//cout<<">>>>>S2<<<<<"<<endl;
while(can[i].x<=mins/2&&now+can[i].x<=m&&i<n){
ans++;
now+=can[i].x;
can[i].f=1;
//cout<<"i1:"<<can[i].x<<endl;
i++;
}
int h=i;
//cout<<"now:"<<now<<endl<<"ans:"<<ans<<endl;
ans+=(m-now)/mins*2;
//cout<<(m-now)<<' '<<(m-now)/mins<<endl;
now+=((m-now)/mins)*mins;
sort(can,can+n,cmp2);
//cout<<"now:"<<now<<endl<<"ans:"<<ans<<endl;;
i=0;
//cout<<">>>>>S3<<<<<"<<endl;
while(now<=m&&i<n&&now+can[i].y<=m){
if(can[i].f){
ans++;
now+=can[i].y;
//cout<<can[i].y<<endl;
}i++;
}
while(can[h].x+now<=m&&h<n){
if(can[h].f==0){
now+=can[h].x;
//cout<<ans<<endl;
ans++;
can[h].f=1;
}h++;
}
cout<<ans;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...