2017-5-1-Train:Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)

A. Arrays(思维)

You are given two arrays A and B consisting of integers, sorted in non-decreasing order. Check whether it is possible to choose knumbers in array A and choose m numbers in array B so that any number chosen in the first array is strictly less than any number chosen in the second array.

Input

The first line contains two integers n**A, n**B (1 ≤ n**A, n**B ≤ 105), separated by a space — the sizes of arrays A and B, correspondingly.

The second line contains two integers k and m (1 ≤ k ≤ n**A, 1 ≤ m ≤ n**B), separated by a space.

The third line contains n**A numbers a1, a2, ... anA ( - 109 ≤ a1 ≤ a2 ≤ ... ≤ anA ≤ 109), separated by spaces — elements of array A.

The fourth line contains n**B integers b1, b2, ... bnB ( - 109 ≤ b1 ≤ b2 ≤ ... ≤ bnB ≤ 109), separated by spaces — elements of array B.

Output

Print "YES" (without the quotes), if you can choose k numbers in array A and m numbers in array B so that any number chosen in arrayA was strictly less than any number chosen in array B. Otherwise, print "NO" (without the quotes).

Examples

input

3 3
2 1
1 2 3
3 4 5

output

YES

input

3 3
3 3
1 2 3
3 4 5

output

NO

input

5 2
3 1
1 1 1 1 1
2 2

output

YES

Note

In the first sample test you can, for example, choose numbers 1 and 2 from array A and number 3 from array B (1 < 3 and 2 < 3).

In the second sample test the only way to choose k elements in the first array and m elements in the second one is to choose all numbers in both arrays, but then not all the numbers chosen in A will be less than all the numbers chosen in B: .

Code:

 1 #pragma comment(linker, "/STACK:36777216")
 2
 3 #include <bits/stdc++.h>
 4 using namespace std;
 5 #define LSON            id << 1 , l , mid
 6 #define RSON            id << 1 | 1 , mid + 1 , r
 7 #define ROOT            1 , 1 , n
 8 #define CLR(x , y)      memset(x , y , sizeof(x))
 9 #define LOWBIT(x)       x & (-x)
10 #define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
11 #define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
12 #define CASE(x)        printf("Case %d: ", x)
13 #define SFD(x)      scanf("%lf" , &x)
14 #define SFC(x)      scanf(" %c" , &x)
15 #define SFS(x)      scanf(" %s" , x)
16 #define SFI(x)      scanf("%d" , &x)
17 #define SFI64(x)    scanf("%I64d" , &x)
18 #define PFF(x)         printf("%f" , x)
19 #define PFD(x)         printf("%lf" , x)
20 #define PFI(x)         printf("%d" , x)
21 #define PFC(x)         printf("%c" , x)
22 #define PFS(x)         printf("%s" , x)
23 #define PFI64(x)       printf("%I64d" , x)
24 #define SPACE          printf(" ")
25 #define PUT            puts("")
26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
28 #define PB(x)          push_back(x)
29 #define ALL(A)         A.begin(), A.end()
30 #define SZ(A)          int((A).size())
31 #define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
32 #define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
33 #define LOCAL
34 static const double PI = acos(-1.0);
35 static const double EPS = 1e-8;
36 static const int INF = 0X3fffffff;
37 typedef double DB;
38 template<class T> inline
39 void read(T &x)
40 {
41     x = 0;
42     int f = 1 ; char ch = getchar();
43     while (ch < ‘0‘ || ch > ‘9‘) {if (ch == ‘-‘) f = -1; ch = getchar();}
44     while (ch >= ‘0‘ && ch <= ‘9‘) {x = x * 10 + ch - ‘0‘; ch = getchar();}
45     x *= f;
46     return ;
47 }
48
49 /************************Little Pea****************************/
50
51 static const int MAXN = 1e5 + 10;
52 int k , m;
53 int na , nb;
54 int da[MAXN] , db[MAXN];
55 int main()
56 {
57 #ifndef ONLINE_JUDGE
58     freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
59 #endif
60     read(na);read(nb);
61     read(k);read(m);
62     LPUP(i , 1 , na)
63     {
64         read(da[i]);
65     }
66     LPUP(i , 1 , nb)
67     {
68         read(db[i]);
69     }
70     int mxa , mib;
71     mxa = da[k];
72     mib = db[nb - m + 1];
73     if(mib > mxa)
74         puts("YES");
75     else
76         puts("NO");
77
78 #ifndef ONLINE_JUDGE
79     fclose(stdin), fclose(stdout);
80 #endif
81 }

B. Order Book(计数排序)

In this task you need to process a set of stock exchange orders and use them to create order book.

An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price p**i, direction d**i — buy or sell, and integer q**i. This means that the participant is ready to buy or sell q**i stocks at price p**i for one stock. A value q**i is also known as a volume of an order.

All orders with the same price p and direction d are merged into one aggregated order with price p and direction d. The volume of such order is a sum of volumes of the initial orders.

An order book is a list of aggregated orders, the first part of which contains sell orders sorted by price in descending order, the second contains buy orders also sorted by price in descending order.

An order book of depth s contains s best aggregated orders for each direction. A buy order is better if it has higher price and a sell order is better if it has lower price. If there are less than s aggregated orders for some direction then all of them will be in the final order book.

You are given n stock exhange orders. Your task is to print order book of depth s for these orders.

Input

The input starts with two positive integers n and s (1 ≤ n ≤ 1000, 1 ≤ s ≤ 50), the number of orders and the book depth.

Next n lines contains a letter d**i (either ‘B‘ or ‘S‘), an integer p**i (0 ≤ p**i ≤ 105) and an integer q**i (1 ≤ q**i ≤ 104) — direction, price and volume respectively. The letter ‘B‘ means buy, ‘S‘ means sell. The price of any sell order is higher than the price of any buy order.

Output

Print no more than 2s lines with aggregated orders from order book of depth s. The output format for orders should be the same as in input.

Examples

input

6 2
B 10 3
S 50 2
S 40 1
S 50 6
B 20 4
B 25 10

output

S 50 8
S 40 1
B 25 10
B 20 4

Note

Denote (x, y) an order with price x and volume y. There are 3 aggregated buy orders (10, 3), (20, 4), (25, 10) and two sell orders (50, 8), (40, 1) in the sample.

You need to print no more than two best orders for each direction, so you shouldn‘t print the order (10 3) having the worst price among buy orders.

Code:

  1 #pragma comment(linker, "/STACK:36777216")
  2
  3 #include <bits/stdc++.h>
  4 using namespace std;
  5 #define LSON            id << 1 , l , mid
  6 #define RSON            id << 1 | 1 , mid + 1 , r
  7 #define ROOT            1 , 1 , n
  8 #define CLR(x , y)      memset(x , y , sizeof(x))
  9 #define LOWBIT(x)       x & (-x)
 10 #define FORN(i , a , n)  for(int i = (a) ; i <= (n) ; ++i)
 11 #define FORP(i , n , a)  for(int i = (n) ; i >= (a) ; --i)
 12 #define CASE(x)        printf("Case %d: ", x)
 13 #define SFD(x)      scanf("%lf" , &x)
 14 #define SFC(x)      scanf(" %c" , &x)
 15 #define SFS(x)      scanf(" %s" , x)
 16 #define SFI(x)      scanf("%d" , &x)
 17 #define SFI64(x)    scanf("%I64d" , &x)
 18 #define PFF(x)         printf("%f" , x)
 19 #define PFD(x)         printf("%lf" , x)
 20 #define PFI(x)         printf("%d" , x)
 21 #define PFC(x)         printf("%c" , x)
 22 #define PFS(x)         printf("%s" , x)
 23 #define PFI64(x)       printf("%I64d" , x)
 24 #define SPACE          printf(" ")
 25 #define PUT            puts("")
 26 #define LPUP(i , j , k) for(int i = j ; i <= k ; ++i)
 27 #define LPDW(i , j , k) for(int i = j ; i >= k ; --i)
 28 #define PB(x)          push_back(x)
 29 #define ALL(A)         A.begin(), A.end()
 30 #define SZ(A)          int((A).size())
 31 #define LBD(A, x)      (lower_bound(ALL(A), x) - A.begin())
 32 #define UBD(A, x)      (upper_bound(ALL(A), x) - A.begin())
 33 #define LOCAL
 34 static const double PI = acos(-1.0);
 35 static const double EPS = 1e-8;
 36 static const int INF = 0X3fffffff;
 37 typedef double DB;
 38 template<class T> inline
 39 T read(T &x)
 40 {
 41     x = 0;
 42     int f = 1 ; char ch = getchar();
 43     while (ch < ‘0‘ || ch > ‘9‘) {if (ch == ‘-‘) f = -1; ch = getchar();}
 44     while (ch >= ‘0‘ && ch <= ‘9‘) {x = x * 10 + ch - ‘0‘; ch = getchar();}
 45     x *= f;
 46 }
 47
 48 /************************Little Pea****************************/
 49
 50 static const int OO = 0x3fffffff;
 51 static const int MAXN = 1e5 + 10;
 52 int S[MAXN];
 53 int B[MAXN];
 54 int n , s;
 55 int main()
 56 {
 57 #ifndef ONLINE_JUDGE
 58     freopen("D:\\系统优化\\Desktop\\littlepea\\in.data" , "r" , stdin);
 59 #endif
 60     read(n);read(s);
 61     int hs = 0 , hb = 0;
 62     LPUP(i , 1 , n)
 63     {
 64         char c ;
 65         int p , q;
 66         SFC(c);read(p);read(q);
 67         if(c == ‘S‘)
 68         {
 69             S[p] += q;
 70         }
 71         else
 72         {
 73             B[p] += q;
 74         }
 75     }
 76     int i = 0;
 77     for(; i <= 100000 && hs < s ; ++i)
 78     {
 79         if(S[i])
 80             ++hs;
 81     }
 82     LPDW(j , i - 1 , 0)
 83     {
 84         if(S[j])
 85             printf("S %d %d\n" , j , S[j]);
 86     }
 87     i = 100000;
 88     for(; i >= 0 && hb < s ; --i)
 89     {
 90         if(B[i])
 91             ++hb;
 92     }
 93     LPDW(j , 100000 , i + 1)
 94     {
 95         if(B[j])
 96             printf("B %d %d\n" , j , B[j]);
 97     }
 98
 99 #ifndef ONLINE_JUDGE
100     fclose(stdin), fclose(stdout);
101 #endif
102 }

时间: 2024-12-18 14:42:34

2017-5-1-Train:Codeforces Round #317 [AimFund Thanks-Round] (Div. 2)的相关文章

【Codeforces Round 1132】Educational Round 61

Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来,但被\(hack\)了...被\(hack\)的原因是没有想到答案会超过\(10^{12}\)(毕竟这个时间上的优化也是在最后迫不得已的情况下加的,就没有考虑正确性... Codeforces 1132 C 题意:给一些区间\([l_i,r_i]\),从中删掉两个,求剩下的区间最多能够覆盖的格子数

codeforces水题100道 第二十五题 Codeforces Round #197 A. Helpful Maths (Div. 2) (strings)

题目链接:http://www.codeforces.com/problemset/problem/339/A题意:重新组合加法字符串,使得按照1,2,3的顺序进行排列.C++代码: #include <iostream> #include <string> using namespace std; int cnt[3]; string s, ans = ""; int main() { cin >> s; int len = s.length();

[codeforces Mail.Ru Cup 2018 Round 1 D][ xor 操作]

http://codeforces.com/contest/1054/problem/D 题目大意:一个序列a1 a2...an,可以对若干个元素进行取反,使所得的新序列异或和为0的区间个数最多. 题目分析:首先易知每个位置的前缀异或和的值只有两种,因为对元素进行取反时,取偶数个元素异或和不变,奇数个元素就是原值取反.然后由于对一个位置取反,不会影响后面位置与这个位置的前缀异或和相同的位置个数(因为这个位置取反后,后面各个位置的前缀异或和也跟着改变),所以一个位置的改变只会影响与前面位置前缀和相

codeforces Intel Code Challenge Final Round (div.1 + div.2 combined)

比赛水掉3题rk559 rating+115 赛后切掉C n年没打cf了终于又重新变蓝了,果然太弱... 1.A题  Checking the Calendar 给定两个星期几,问是否可能分别是两个月的第一天. 水题暴力枚举月份 #include<cstdio> #include<cstring> #include<cstdlib> #include<vector> #include<algorithm> #include<function

Codeforces Forethought Future Cup Elimination Round 选做

施工中... 1146C Tree Diameter 题意 交互题.有一棵 \(n(n\le 100)\) 个点的树,你可以进行不超过 \(9\) 次询问,每次询问两个点集中两个不在同一点集的点的最大距离.求树的直径. 题解 和 GXOI2019旅行者基本类似,二进制分组,对于每一位,编号当前位为 \(0\) 的分到一组,当前位为 \(1\) 的分到另一组.最大询问次数为 \(\log 100 = 7\) #include<cstdio> int v1[105],v2[105]; int ma

Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include<bits/stdc++.h> #define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to) #define dbg(...) fprintf(stderr, __VA_ARGS__) #define F

Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会吃掉(不会留给后面的人). 如果有人什么都没吃就会不开心,问怎么安排使不开心的人最少. 思路: 看成一个图的问题,点心是节点,人是一条边.对于每个连通块,总会有一个人吃两个点心,其他人吃一个(其中一个是其他人也就吃掉了的). 可以保证这样是最优的,所有每个连通块的答案是连通数 x-1. 1 #def

Round #423 B. Black Square(Div.2)

Polycarp has a checkered sheet of paper of size n?×?m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that

Round #423 A.Restaurant Tables(Div.2)

In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. I