E. Exposition

本文介绍了一个算法问题,旨在为即将到来的作家Berlbury的五十岁生日庆祝活动选择一系列书籍进行展示。目标是选出高度差异不超过特定值k的尽可能多的书籍,并确定这些书籍的出版时间段。通过使用多集合和滑动窗口技术,该算法能够高效地解决这个问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

                                                                    E. Exposition
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

There are several days left before the fiftieth birthday of a famous Berland's writer Berlbury. In this connection the local library decided to make an exposition of the works of this famous science-fiction writer. It was decided as well that it is necessary to include into the exposition only those books that were published during a particular time period. It is obvious that if the books differ much in size, the visitors will not like it. That was why the organizers came to the opinion, that the difference between the highest and the lowest books in the exposition should be not more than k millimeters.

The library has n volumes of books by Berlbury, arranged in chronological order of their appearance. The height of each book in millimeters is know, it is hi. As Berlbury is highly respected in the city, the organizers want to include into the exposition as many books as possible, and to find out what periods of his creative work they will manage to cover. You are asked to help the organizers cope with this hard task.

Input

The first line of the input data contains two integer numbers separated by a space n (1 ≤ n ≤ 105) and k (0 ≤ k ≤ 106) — the amount of books by Berlbury in the library, and the maximum allowed height difference between the lowest and the highest books. The second line contains n integer numbers separated by a space. Each number hi (1 ≤ hi ≤ 106) is the height of the i-th book in millimeters.

Output

In the first line of the output data print two numbers a and b (separate them by a space), where a is the maximum amount of books the organizers can include into the exposition, and b — the amount of the time periods, during which Berlbury published a books, and the height difference between the lowest and the highest among these books is not more than k milllimeters.

In each of the following b lines print two integer numbers separated by a space — indexes of the first and the last volumes from each of the required time periods of Berlbury's creative work.

Sample test(s)
input
3 3
14 12 10
output
2 2
1 2
2 3
input
2 0
10 10
output
2 1
1 2
input
4 5
8 19 10 13
output
2 1
3 4
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <set>
 4 using namespace std;
 5 int a[10000000],c[100000];
 6 int main()
 7 {
 8     int n,k,i,b=0,max=0,p=0;
 9     scanf("%d%d",&n,&k);
10     multiset<int> z;
11     for(i=0; i<n; i++)
12     {
13         scanf("%d",&a[i]);
14         z.insert(a[i]);
15         while(*z.rbegin()-*z.begin()>k)z.erase(z.find(a[b++]));
16         if(i-b+1>max)
17         {
18             max=i-b+1,p=0;c[p++]=b;
19         }
20         else if(i-b+1==max)
21         {
22             c[p++]=b;
23         }
24     }
25     cout<<max<<" "<<p<<endl;
26     for(i=0; i<p; i++)
27         printf("%d %d\n",c[i]+1,c[i]+max);
28 }
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3575677.html

postman返回的数据没有三级菜/** * 根获取菜单表aId对应的权限 * @auther wzy * @return 动态路由 */ @GetMapping("/getMenuList") public Result getMenuList(){ // 从 ThreadLocal 获取 aId Map<String, Object> map = ThreadLocalUtil.get(); Long aId = (Long) map.get("aId"); System.out.println("aid:" + aId); List<MenuDTO> list = null; try { list = menuService.getUserMenuListById(aId); System.out.println("列表"+list); } catch (Exception e) { e.printStackTrace(); return Result.error("获取路由失败: " + e.getMessage()); } return Result.success(list); }List<MenuDTO> getUserMenuListById(Long aId); <select id="selectAuthorizedMenus" resultType="com.example.enterprise_exposition.pojo.Menu"> WITH RECURSIVE authorized_menus AS ( -- 初始查询(非递归部分) SELECT ram.m_id, CAST(ram.m_id AS CHAR(255)) AS path -- 可选路径追踪 FROM role r JOIN role_and_menu ram ON r.r_id = ram.r_id WHERE r.a_id = #{aId} UNION -- 递归部分 SELECT m.m_id, CONCAT(am.path, '->', m.m_id) FROM menu m INNER JOIN authorized_menus am ON m.m_father = am.m_id ) SELECT DISTINCT m.* FROM authorized_menus am JOIN menu m ON am.m_id = m.m_id -- 直接连接CTE结果 ORDER BY m.m_id; </select> @Override public List<MenuDTO> getUserMenuListById(Long aId) { return getMenuTree(aId); } private List<MenuDTO> getMenuTree(Long aId) { List<Menu> menus = baseMapper.selectAuthorizedMenus(aId); return buildTree(menus); } private List<MenuDTO> buildTree(List<Menu> menus) { Map<Long, MenuDTO> dtoMap = new HashMap<>(); List<MenuDTO> rootNodes = new ArrayList<>(); // 第一遍遍历:创建所有DTO对象 menus.forEach(menu -> { MenuD单
03-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值