陶陶摘苹果(升级版)c++(基础分开算)

简介: 陶陶摘苹果(升级版)c++(基础分开算)

The topic is as follows

It's autumn again, and Tao Tao's apple tree bears n fruits. Tao Tao ran to pick apples again, this time he had a chair measuring a centimeter. When he can't reach, he will stand on the chair and try again.


This time, the difference from the first question of the popularization group of NOIp2005 is: Tao Tao moved the stool before, and only s strength is left. Of course, every time you pick an apple, you have to use a certain amount of strength. Tao Tao wants to know how many apples can be picked at most before s<0.


It is now known that n apples reach the height of the ground xi, the height of the chair a, the maximum length of the pottery hand stretched b, the remaining strength of the pottery s, the strength required for the pottery to pick an apple, yi, the pottery can be picked at most How many apples.


Input format


Line 1: Two numbers, number of apples, n, strength s.


Line 2: Two numbers The height of the chair a, the maximum length of the Taotao hand stretched b.


Row 3~row 3+n−1: Two numbers per row The height of the apple xi, the strength required to pick this apple yi.


There is only one integer, which represents the maximum number of apples that Tao Tao can pick.


Enter

8 15

20 130

120 3

150 2

110 7

180 1

50 8

200 0

140 3

120 2


Output

4


Problem analysis This is a simulated printing problem. We first rank the least effortlessly first, and then we can use the height to judge, so that we are always picking the least effortlessly, so that we can get the most apples.


#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+6;
struct node{
  int x,y;
}s[maxn];
bool cmp(node q,node w)
{
  return q.y<w.y;
}
int main()
{
  int n,z,a,b;
  int ans=0;
  cin>>n>>z>>a>>b;
  for(int i=1;i<=n;i++)
  {
    cin>>s[i].x;
    cin>>s[i].y;
  }
  sort(s+1,s+1+n,cmp);
  for(int i=1;i<=n&&z>=0;i++)
  {
    if(s[i].x<=a+b&&z-s[i].y>=0)
    {
      z-=s[i].y;
      ans++;
    } 
  }
  cout<<ans<<endl;
}


相关文章
|
1月前
|
Linux 编译器 测试技术
【C++】CentOS环境搭建-快速升级G++版本
通过上述任一方法,您都可以在CentOS环境中高效地升级G++至所需的最新版本,进而利用C++的新特性,提升开发效率和代码质量。
160 64
|
1月前
|
Linux 编译器 测试技术
【C++】CentOS环境搭建-快速升级G++版本
通过上述任一方法,您都可以在CentOS环境中高效地升级G++至所需的最新版本,进而利用C++的新特性,提升开发效率和代码质量。
193 63
|
6月前
|
监控 安全 Linux
Linux C++ 环境下的FTP远程升级实现及异常处理策略
Linux C++ 环境下的FTP远程升级实现及异常处理策略
193 0
|
6月前
|
存储 C++
c++类和对象一对象特性一成员变量和成员函数分开存储
c++类和对象一对象特性一成员变量和成员函数分开存储
38 0
|
11月前
|
C语言 C++
为DEV C++升级MinGW版本
为了安装easyx,但是原来的5.11版本跟着教程 https://codebus.cn/bestans/easyx-for-mingw 但是mingw版本太老了,无法使用 期间也尝试小熊猫dev和小龙版dev,但是他们修改后的界面风格不习惯,最终还是决定升级原来的dev c++就好了。
194 0
|
存储 安全 编译器
【C++杂货铺】C++11特性总结:列表初始化 | 声明 | STL的升级
【C++杂货铺】C++11特性总结:列表初始化 | 声明 | STL的升级
79 0
|
C++
搞懂C++的虚拟继承(升级)
搞懂C++的虚拟继承(升级)
111 4
搞懂C++的虚拟继承(升级)
|
iOS开发
Xcode 10升级报错:libstdc++.6.0.9.tbd
Xcode 10升级报错:libstdc++.6.0.9.tbd
857 0
Xcode 10升级报错:libstdc++.6.0.9.tbd
|
人工智能 Linux C++
Visual Studio 2022 正式版发布:升级为 64 位、支持 .NET 6 和 C++ 20
Visual Studio 2022 正式版发布:升级为 64 位、支持 .NET 6 和 C++ 20
479 0
Visual Studio 2022 正式版发布:升级为 64 位、支持 .NET 6 和 C++ 20
|
C++
【简讯】ISO确定C++的升级
随着ISO督导委员会C++语言组对该语言下一版规格说明最终草案的敲定, C++编程语言即将换代升级。 ISO/IEC信息技术特别小组将会审查督导委员会的最终草案是否符合国际标准,不出任何意外,将于今年晚期出版该草案。
656 0