Minibus

Time limit: 1.0 second
Memory limit: 64 MB

Background

Minibus driver Sergey A. Greedson has become totally famous for his phenomenal greediness. He claimed time and again that he held himself in readiness to throttle his brother and sell out all friends for an extra cent. Unfortunately, these statements were impossible to verify because Sergey had got neither brothers nor friends, home or family. And he had not got any money either. An old minibus seemed to be the only property of Mr. Greedson. So he traveled the city giving occasional passengers a lift and sometimes examining pavements for dumps...
One day the heavens took pity on Sergey and decided to stop his useless being in out cruel world. For this noble purpose an axe fell down on the head of carefree Mr. Greedson, who had just left the minibus on account of inviting shine of an empty beer bottle. The dreams of profitable bottle sale went out of his head in a blink replaced by the axe. In a figurative sense, of course. Heavens tool could not break a stiff skull of Mr. Greedson but, as it turned out later, gave him several rather useful abilities.
Soon after the axe was sold, Sergey discovered his ability to foresee the future. What a scope, what a prospect was given to the artless minibus driver! Who are we and where are we going? What is to be feared and hoped? The answers for these questions did not worry Mr. Greedson at all. But Sergey's greedy mind was clever enough to use his new ability to earn some money. As many others, Mr. Greedson was absolutely sure that the easiest way to enrichment was to fleece working-people, in other words, the passengers of his own minibus.

Problem

Every day the minibus makes a passage from 1-st to N-th bus stop. There are M passenger seats in the minibus. Once in the evening Mr. Greedson has counted the probability lines and found out that the next day K persons would wait for the minibus on the bus stops. For each person the number of bus stop S[i], where he wants to get into the minibus, and the number of bus stop F[i], where he is going to leave the minibus, were found. According to Sergey's pricing policy, each passenger must pay P dollars for a ticket despite the number of passed bus stops. More over, at a bus stop Mr. Greedson may allow some persons to get into the minibus and ban others (in other words, he may choose his passengers himself). After the problem was posed to maximize the gain, Sergey decided to find the persons who should be allowed to get into the minibus. Unfortunately, he does not possess enough power to perform it. And what about you?

Input

The first line contains integer numbers N (2 ≤ N ≤ 100000), M (1 ≤ M ≤ 1000), K (0 ≤ K ≤ 50000) and P (1 ≤ P ≤ 10000). Each of the next K lines contains the integer numbers S[i] and F[i] (1 ≤ S[i] < F[i] ≤ N) for the corresponding passenger.

Output

The first line should contain the maximal gain. The second line should contain the numbers of persons, who should be allowed to get into the minibus to obtain this gain. The numbers should be listed in any order and separated by single spaces. If the problem has several solutions, you should output any of them.

Sample

input output
6 2 6 9
1 4
2 6
1 5
2 3
4 6
3 6
36
1 5 6 4

分析:贪心+线段树;

   按结束时间排序,则尽可能让座位坐满,线段树区间更新判断是否可坐;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t;
vi ans;
struct node
{
int x,y,id;
bool operator<(const node&p)const
{
return y<p.y;
}
}a[maxn];
struct Node
{
int Max, lazy;
} T[maxn<<]; void PushUp(int rt)
{
T[rt].Max = max(T[rt<<].Max, T[rt<<|].Max);
} void PushDown(int L, int R, int rt)
{
int mid = (L + R) >> ;
int t = T[rt].lazy;
T[rt<<].Max += t;
T[rt<<|].Max += t;
T[rt<<].lazy += t;
T[rt<<|].lazy += t;
T[rt].lazy = ;
} void Update(int l, int r, int v, int L, int R, int rt)
{
if(l==L && r==R)
{
T[rt].lazy += v;
T[rt].Max += v;
return ;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) Update(l, r, v, Lson);
else if(l > mid) Update(l, r, v, Rson);
else
{
Update(l, mid, v, Lson);
Update(mid+, r, v, Rson);
}
PushUp(rt);
} int Query(int l, int r, int L, int R, int rt)
{
if(l==L && r== R)
{
return T[rt].Max;
}
int mid = (L + R) >> ;
if(T[rt].lazy) PushDown(L, R, rt);
if(r <= mid) return Query(l, r, Lson);
else if(l > mid) return Query(l, r, Rson);
return max(Query(l, mid, Lson) , Query(mid + , r, Rson));
}
int main()
{
int i,j;
scanf("%d%d%d%d",&n,&m,&k,&t);
rep(i,,k)scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
sort(a+,a+k+);
rep(i,,k)
{
if(Query(a[i].x,a[i].y-,,n,)<m)
{
ans.pb(a[i].id);
Update(a[i].x,a[i].y-,,,n,);
}
}
printf("%lld\n",(ll)ans.size()*t);
if(ans.size())printf("%d",ans[]);
for(i=;i<ans.size();i++)printf(" %d",ans[i]);
printf("\n");
//system("Pause");
return ;
}

ural1424 Minibus的更多相关文章

  1. English word

    第一部分  通过词缀认识单词 (常用前缀一) 1.a- ①加在单词(形容词)或词根前面,表示"不,无,非" acentric [ə'sentrik] a  无中心的(a+centr ...

  2. UVA12653 Buses

    Problem HBusesFile: buses.[c|cpp|java]Programming competitions usually require infrastructure and or ...

  3. TensorFlow和最近发布的slim

    笔者将和大家分享一个结合了TensorFlow和最近发布的slim库的小应用,来实现图像分类.图像标注以及图像分割的任务,围绕着slim展开,包括其理论知识和应用场景. 之前自己尝试过许多其它的库,比 ...

  4. e-olymp Problem8352 Taxi

    作为我在这个OJ玩了一下午的终结吧. 水题一道,阅读理解OJ. 传送门:点我 Taxi At the peak hour, three taxi buses drove up at the same ...

  5. 微信emoji的code

    const MAP = [        "\xc2\xa9" => 'COPYRIGHT SIGN',        "\xc2\xae" => ...

  6. Codeforces Beta Round #9 (Div. 2 Only) B. Running Student 水题

    B. Running Student 题目连接: http://www.codeforces.com/contest/9/problem/B Description And again a misfo ...

  7. github提交表情包

    emoji-list emoji表情列表 目录 人物 自然 事物 地点 符号 人物 :bowtie: :bowtie: :smile: :smile: :laughing: :laughing: :b ...

  8. Preparing Cities for Robot Cars【城市准备迎接自动驾驶汽车】

    Preparing Cities for Robot Cars The possibility of self-driving robot cars has often seemed like a f ...

  9. BEC listen and translation exercise 42

    These were built for the workers towards the end of the eighteenth century, and they are still furni ...

随机推荐

  1. Google 怎么搜索

    著作权归作者所有. 商业转载请联系作者获得授权,非商业转载请注明出处. 作者:崔凯 链接:http://www.zhihu.com/question/20161362/answer/14180620 ...

  2. android之ViewStub的使用

    转自http://blog.csdn.net/hitlion2008/article/details/6737537 在开发应用程序的时候,经常会遇到这样的情况,会在运行时动态根据条件来决定显示哪个V ...

  3. LoadRunner编写Socket协议脚本方法

    本文主要介绍使用LoadRunner手工编写Windows Socket协议测试脚本的方法. 通过LoadRunner编写Windows Socket协议测试脚本,总体说来,比较简单.就像把大象放进冰 ...

  4. Tomcat目录下文件详解

    一.Tomcat背景   (转) 自从JSP发布之后,推出了各式各样的JSP引擎.Apache Group在完成GNUJSP1.0的开发以后,开始考虑在SUN的JSWDK基础上开发一个可以直接提供We ...

  5. java写文件时,输出不完整的原因以及解决方法close()或flush()

    在java的IO体系中,写文件通常会用到下面语句 BufferedWriter bw=new BufferedWriter(new FileWriter("sql语句.txt")) ...

  6. Sharepoint 弹出消息提示框 .

    在event receiver中如何弹出一个类似winform中messagebox.show 的框? 那我要对用户显示一些错误信息或者提示信息怎么搞? 1. 如果是在ItemAdding或者其他进行 ...

  7. sqldeveloper连接mysql

    sqldeveloper连接mysql 腑镜诏 钌d 汁叁ㄧ勋 佚蔡弥噙 不仅仅是越南帮和戴爷的事情还有谢婉莹的条 炔验遒其 倒扇油┣ 砹笄谤 几句话孟飞的信心大增兴奋不已换句话说 谠诂k厝 ...

  8. screen 链接远程桌面

    screen     开一个新的screen窗口 screen -ls 查看已经存在的所有screen窗口 screen -r  208111  进入这个窗口 ctrl+a+d  退出screen,回 ...

  9. 编译安装SVN不结合apache

    前言:独立SVN服务器不结合APACHE安装使用,连接独立SVN服务器也不是用HTTP协议.这是比较快捷的SVN服务器配置方法. 一.下载工具 1.subversion-1.6.17.tar.gz 2 ...

  10. mysql innobackupex备份工具

    先简单介绍一下这个工具:innobackupexinnobackupex比xtarbackup有更强的功能,它整合了xtrabackup和其他的一些功能,他不但可以全量备份/恢复,还可以基于时间的增量 ...