Dragons and Princesses(优先队列)

在一个由牢房组成的路径上,一位骑士踏上寻找真爱的冒险旅程。面对沿途的龙与公主,骑士的目标是在收集最多金币的同时成功赢得终点处公主的芳心。

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

Once upon a time there lived the Knight. Being very courageous he decided to make a long journey full of fights and adventures. The map of this journey can be represented as a row with n cells numbered from 1 to nfrom left to right. Initially the Knight is located at the leftmost cell (cell number 1). He should pass all the cells one by one and finish his way at the rightmost cell (cell number n). He is not allowed to move back or skip some cells, he will visit all the cells from the first to the last.

Each cell except the first one contains either a dragon or a princess. Each dragon has a chest with gold coins. The dragon at the cell i keeps gi coins. Every time the Knight steps to a cell with a dragon he has a choice  — to kill the dragon or just to pass through. The Knight is very strong and dexterous, so it is not a problem for him to kill any dragon on his way. If a dragon is killed the Knight gets all the gold dragon possessed.

When the Knight steps to the cell with a princess, she wonders how many dragons he has killed. If that number is greater or equal to her beauty bi, the princess considers the Knight brave enough and instantly asks him to marry her. Being a true gentleman, the Knight cannot refuse and his adventure immediately ends.

The Knight loves the princess who lives in the cell number n and wants to marry her. Also during the journey he wants to collect as much gold as possible. Please help him to accomplish this task.

Input

The first line of the input contains a single integer n (2 ≤ n ≤ 2·105) — the number of cells. The next n-1 lines describe cells from 2 to n

If the cell number i contains a dragon, the i-th line of the input contains letter "
d
" followed by a single integer gi(1 ≤ gi ≤ 104) — the number of coins the dragon keeps. The letter and the integer are separated by a single space.

If the cell number i contains a princess, the i-th line of the input contains letter "
p
" followed by a single integer bi(1 ≤ bi ≤ 2·105) — the beauty of the princess. The letter and the integer are separated by a single space. It is guaranteed that the last cell contains a princess.

Output

On the first line of the output print a single integer — the maximum number of gold coins the Knight can collect. On the second line print a single integer k — the number of dragons to kill. The third line should contain kintegers — the numbers of the cells where the Knight should kill a dragon. The cell numbers should be printed in the increasing order.

If there are several optimal solutions, output any of them. If the Knight can't marry his beloved princess, just print 
-1
 in the first line of the output.

Sample Input

Example(s)
sample input
sample output
6
d 10
d 12
p 2
d 1
p 2
13
2
3 5
题意 :   有一条牢房,n个牢房排成一条线,骑士从左第一个牢房往右走,不能回头.每个牢房有一条龙或者有一个公主..  杀了龙获得黄金,遇见公主,如果杀的龙的数量不小于公主的期望值,则娶公主.......骑士尽可能的获得多的黄金,同时他只想取最后一个牢房的公主(保证最后一个牢房一定有公主) ,这就要求在娶最后公主之前,不能娶别的公主,也就是杀龙的数量的不能超过公主的期望值,不然就会娶了别的公主....
 

· 
#include
<iostream>

·  #include<cstdio>

·  #include<cstdlib>

·  #include<cmath>

·  #include<cstring>

·  #include<string>

·  #include<vector>

·  #include<list>

·  #include<map>

·  #include<set>

·  #include<stack>

·  #include<queue>

·  #include<algorithm>

·  #include<functional

·  usingnamespace std;

·  #define N200005

·  ·  structnode

·  {

·  int x,id; //x是黄金数,或者公主期望值.  id为第几个牢房.

·  char tp[2];

·  booloperator<(nodea)const{ //重载运算符,按升序排列

·  if(x<a.x)return0;

·  elsereturn1;

·  }

·  }a[N],ans[N];

·  priority_queue<node>q;     //优先队列

·  intcmp(nodex,nodey)         //升序排列牢房编号

·  {

·  return x.id<y.id;

·  }

·  //priority_queue<int,vector<int>,greater<int>> q;

·  intmain()

·  {

·  int n,i;

·  while(scanf("%d",&n)==1)

·  {

·  //getchar();

·  for(i=1;i<n;i++)

·  scanf("%s%d",&a[i].tp,&a[i].x),a[i].id=i+1;      //因为牢房是从2到n;骑士刚开始在第一个牢房出发,所以加1

·  while(!q.empty())q.pop();             //初始化容器,使容器为空.

·  for(i=1;i<n-1;i++)

·  {

·  if(a[i].tp[0]=='d')q.push(a[i]);        //如牢房是龙,加入容器

·  else{                       //q.size()是返回容器的容量,即元素的个数.

·                    //若是公主,判断容器里龙的数量是否大于公主的期望值,大于,就移除容器元素.

·  while(q.size()>=a[i].x)q.pop()   //知道龙的数量小于公主的期望,移除的龙是按黄金数小的优先出来.

·  }    //最后容器的里面的龙斗士要杀的,并且黄金数是最大的.

·  }    //若容器的容量小于最后一个公主的期望,即不能娶最后一个公主,则 -1 ;

·  if(q.size()<a[i].x)printf("-1\n");

·  else{

·  int l=0,cnt=0;

·  while(!q.empty())

·  ans[l++]=q.top(),q.pop();   //取容器里的龙,

·  sort(ans,ans+l,cmp);   //按牢房编号升序排列

·  for(i=0;i<l;i++)cnt+=ans[i].x; //总获得的黄金

·  printf("%d\n",cnt);printf("%d\n",l);

·  for(i=0;i<l-1;i++)printf("%d",ans[i].id);printf("%d\n",ans[i].id); //输出杀龙的编号.

·  }

·  }

·  return0;

·  }



1. 用户与权限管理模块 角色管理: 学生:查看实验室信息、预约设备、提交耗材申请、参与安全考核 教师:管理课题组预约、审批学生耗材申请、查看本课题组使用记录 管理员:设备全生命周期管理、审核预约、耗材采购与分发、安全检查 用户操作: 登录认证:统一身份认证(对接学号 / 工号系统,模拟实现),支持密码重置 信息管理:学生 / 教师维护个人信息(联系方式、所属院系),管理员管理所有用户 权限控制:不同角色仅可见对应功能(如学生不可删除设备信息) 2. 实验室与设备管理模块 实验室信息管理: 基础信息:实验室编号、名称、位置、容纳人数、开放时间、负责人 功能分类:按学科(计算机实验室 / 电子实验室 / 化学实验室)标记,关联可开展实验类型 状态展示:实时显示当前使用人数、设备运行状态(正常 / 故障) 设备管理: 设备档案:名称、型号、规格、购置日期、单价、生产厂家、存放位置、责任人 全生命周期管理: 入库登记:管理员录入新设备信息,生成唯一资产编号 维护记录:记录维修、校准、保养信息(时间、内容、执行人) 报废处理:登记报废原因、时间,更新设备状态为 "已报废" 设备查询:支持按名称、型号、状态多条件检索,显示设备当前可用情况 3. 预约与使用模块 预约管理: 预约规则:学生可预约未来 7 天内的设备 / 实验室,单次最长 4 小时(可设置) 预约流程:选择实验室→选择设备→选择时间段→提交申请(需填写实验目的) 审核机制:普通实验自动通过,高危实验(如化学实验)需教师审核 使用记录: 签到 / 签退:到达实验室后扫码签到,离开时签退,系统自动记录实际使用时长 使用登记:填写实验内容、设备运行情况(正常 / 异常),异常情况需详细描述 违规管理:迟到 15 分钟自动取消预约,多次违规限制预约权限 4. 耗材与安全管理模块 耗材管理: 耗材档案:名称、规格、数量、存放位置、
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值