A. Lunch Rush
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly k time units for the lunch break.

The Rabbits have a list of n restaurants to lunch in: the i-th restaurant is characterized by two integers fi and ti. Value ti shows the time the Rabbits need to lunch in the i-th restaurant. If time ti exceeds the time k that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal fi - (ti - k). Otherwise, the Rabbits get exactly fi units of joy.

Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.

Input

The first line contains two space-separated integers — n (1 ≤ n ≤ 104) and k (1 ≤ k ≤ 109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next n lines contains two space-separated integers — fi (1 ≤ fi ≤ 109) and ti (1 ≤ ti ≤ 109) — the characteristics of the i-th restaurant.

Output

In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.

Examples
Input
2 5
3 3
4 5
Output
4
Input
4 6
5 8
3 6
2 3
2 2
Output
3
Input
1 5
1 7
Output
-1
题意:水
题解:模拟
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
ll n,k;
ll a,b;
ll ans=;
int main()
{
ans=-1e10;
scanf("%I64d %I64d",&n,&k);
for(ll i=;i<=n;i++)
{
scanf("%I64d %I64d",&a,&b);
if(b>k)
ans=max(ans,a-(b-k));
else
ans=max(ans,a);
}
printf("%I64d\n",ans);
return ;
}
B. Little Girl and Game
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The Little Girl loves problems on games very much. Here's one of them.

Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules:

  • The players move in turns; In one move the player can remove an arbitrary letter from string s.
  • If the player before his turn can reorder the letters in string s so as to get a palindrome, this player wins. A palindrome is a string that reads the same both ways (from left to right, and vice versa). For example, string "abba" is a palindrome and string "abc" isn't.

Determine which player will win, provided that both sides play optimally well — the one who moves first or the one who moves second.

Input

The input contains a single line, containing string s (1 ≤ |s|  ≤  103). String s consists of lowercase English letters.

Output

In a single line print word "First" if the first player wins (provided that both players play optimally well). Otherwise, print word "Second". Print the words without the quotes.

Examples
Input
aba
Output
First
Input
abca
Output
Second
题意:给你一个字符串 两个人轮流删除一个字符 在删除之前 若重新组合字符的顺序 使得字符串为回文串 则当前选手获胜
题解:因为题目中说明字符串可以重新排列组合 所以只需要判断初始字符串中每个字符出现的次数 统计出现次数为奇数次的字母的个数 为0或为奇数则先手胜
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
char a[];
map<char,int> mp;
int main()
{
scanf("%s",a);
int len=strlen(a);
for(int i=;i<len;i++)
{
mp[a[i]]++;
}
int ans=;
for(char i='a';i<='z';i++)
{
if(mp[i]%)
ans++;
}
if(ans==||ans%)
printf("First\n");
else
printf("Second\n");
return ;
}
C. Little Girl and Maximum Sum
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

The little girl loves the problems on array queries very much.

One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined by a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). You need to find for each query the sum of elements of the array with indexes from li to ri, inclusive.

The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum.

Input

The first line contains two space-separated integers n (1 ≤ n ≤ 2·105) and q (1 ≤ q ≤ 2·105) — the number of elements in the array and the number of queries, correspondingly.

The next line contains n space-separated integers ai (1 ≤ ai ≤ 2·105) — the array elements.

Each of the following q lines contains two space-separated integers li and ri (1 ≤ li ≤ ri ≤ n) — the i-th query.

Output

In a single line print a single integer — the maximum sum of query replies after the array elements are reordered.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Examples
Input
3 3
5 3 2
1 2
2 3
1 3
Output
25
Input
5 3
5 2 4 1 3
1 5
2 3
2 3
Output
33
题意:给你n个数 q个区间 问你如何排列这n个数 使得q个区间和的和最大 输出这个最大值
题解:统计每个位置在q个区间中出现的次数 升序排列 对于n个数升序排列 相乘求和
可以线段树区间更新单点查询 也可以利用区间更新的姿势。
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
ll n,q;
ll a[];
ll l,r;
ll s[];
ll ans=;
struct node
{
ll w;
}N[];
bool cmp(struct node aa,struct node bb)
{
return aa.w<bb.w;
}
int main()
{
memset(s,,sizeof(s));
scanf("%I64d %I64d",&n,&q);
for(ll i=;i<=n;i++)
scanf("%I64d",&a[i]);
sort(a+,a++n);
for(ll i=;i<=q;i++)
{
scanf("%I64d %I64d",&l,&r);
s[l]++;
s[r+]--;
}
ll exm=;
for(ll i=;i<=n;i++)
{
exm+=s[i];
N[i].w=exm;
}
sort(N+,N++n,cmp);
for(ll i=;i<=n;i++)
ans+=N[i].w*a[i];
printf("%I64d\n",ans);
return ;
}
D. Little Girl and Maximum XOR
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

A little girl loves problems on bitwise operations very much. Here's one of them.

You are given two integers l and r. Let's consider the values of for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones.

Expression means applying bitwise excluding or operation to integers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is represented as "^", in Pascal — as «xor».

Input

The single line contains space-separated integers l and r (1 ≤ l ≤ r ≤ 1018).

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Output

In a single line print a single integer — the maximum value of for all pairs of integers a, b (l ≤ a ≤ b ≤ r).

Examples
Input
1 2
Output
3
Input
8 16
Output
31
Input
1 1
Output
0
题意:给你一个区间 在区间任意选出两个数 输出最大的两数异或和
题解:数据范围最大为2^62 从高位到低位枚举 寻找上下界异或和为1的最高位
 #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#define ll __int64
#define mod 1000000007
#define dazhi 2147483647
using namespace std;
ll l,r;
int main()
{
scanf("%I64d %I64d",&l,&r);
if(l==r)
{
printf("0\n");
return ;
}
ll ans=;
ans=(ll)<<;
while(ans&&(ans&l)==(ans&r)) ans>>=;
printf("%I64d\n",ans*-);
return ;
}

Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路的更多相关文章

  1. Codeforces Round #419 (Div. 2) A B C 暴力 区间更新技巧 +前缀和 模拟

    A. Karen and Morning time limit per test 2 seconds memory limit per test 512 megabytes input standar ...

  2. Codeforces Round #538 (Div. 2) F 欧拉函数 + 区间修改线段树

    https://codeforces.com/contest/1114/problem/F 欧拉函数 + 区间更新线段树 题意 对一个序列(n<=4e5,a[i]<=300)两种操作: 1 ...

  3. Codeforces Round #365 (Div. 2) A 水

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  4. Codeforces Round #404 (Div. 2)(A.水,暴力,B,排序,贪心)

    A. Anton and Polyhedrons time limit per test:2 seconds memory limit per test:256 megabytes input:sta ...

  5. Codeforces Round #408 (Div. 2)(A.水,B,模拟)

    A. Buying A House time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  6. Codeforces Round #394 (Div. 2)A水 B暴力 C暴力 D二分 E dfs

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  7. Codeforces Round #337 (Div. 2) A水

    A. Pasha and Stick time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  8. Codeforces Round #316 (Div. 2) A 水

    A. Elections time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  9. Codeforces Round #362 (Div. 2) A 水也挂

    A. Pineapple Incident time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. POJ 3046

    题目大意:蚂蚁牙黑,蚂蚁牙红:有A只蚂蚁,来自T个家族,分别记为ant[i]个.同一个家族的蚂蚁长得一样,但是不同家族的蚂蚁牙齿颜色不同.任取n只蚂蚁(S <= n <= B),求能组成几 ...

  2. 如何处理 jQuery $(window).resize() 中的方法被多次执行的小问题

    引言: 估计很多同志们在编写浏览器resize()的方法时,都会遇到这样的情况: 当拖动浏览器的边角时,页面中的一些效果随浏览器大小的改变而触发,这一过程开始到结束,resize() 中的方法被执行了 ...

  3. [c++] Getting Started - CMake

    CMake is an open-source cross platform build system, according to CMake's creator, Kitware. But CMak ...

  4. iOS- 网络访问两种常用方式【GET & POST】实现的几个主要步骤

    1.前言 上次,在博客里谈谈了[GET & POST]的区别,这次准备主要是分享一下自己对[GET & POST]的理解和实现的主要步骤. 在这就不多废话了,直接进主题,有什么不足的欢 ...

  5. iOS开发开辟线程总结--NSThread

    1.简介: 1.1 iOS有三种多线程编程的技术,分别是: 1..NSThread 2.Cocoa NSOperation (iOS多线程编程之NSOperation和NSOperationQueue ...

  6. Zigbee安全基础篇Part.2

    原文地址: https://www.4hou.com/wireless/14252.html 导语:本文将会探讨ZigBee标准提供的安全模型,用于安全通信的各种密钥.ZigBee建议的密钥管理方法以 ...

  7. Thinkphp5图片、音频和视频文件上传

    首先是同步上传,最为基础的上传的方式,点击表单提交之后跳转那种.如下前端代码 <!DOCTYPE html> <html lang="en"> <he ...

  8. C#里面Console.Write()和Console.WriteLine()有什么区别?

    Console.Write()和Console.WriteLine()都是System.Console提供的方法,两着主要用来将输出流由指定的输出装置(默认为屏幕)显示出来.两着间的差异在Consol ...

  9. name(实例化类名).hbm.xml文件案例

    [html] view plain copy print? <span xmlns="http://www.w3.org/1999/xhtml"><?xml ve ...

  10. 【bzoj1775】[Usaco2009 Dec]Vidgame 电视游戏问题 dp

    题目描述 输入 * 第1行: 两个由空格隔开的整数: N和V * 第2到第N+1行: 第i+1行表示第i种游戏平台的价格和可以在这种游戏平台上面运行的游 戏.包含: P_i, G_i还有G_i对由空格 ...