Tenka1 Programmer Contest-D
来源:互联网 发布:单片机电子时钟设计 编辑:程序博客网 时间:2024/05/16 23:55
Time limit : 2sec / Memory limit : 256MB
Score : 500 points
Problem Statement
Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is Ai and has a utility of Bi. There may be multiple equal integers with different utilities.
Takahashi will buy some integers in this store. He can buy a combination of integers whose bitwise OR is less than or equal to K. He wants the sum of utilities of purchased integers to be as large as possible.
Find the maximum possible sum of utilities of purchased integers.
Constraints
1≤N≤105
0≤K<230
0≤Ai<230(1≤i≤N)
1≤Bi≤109(1≤i≤N)
All input values are integers.
Inputs
Input is given from Standard Input in the following format:
N K
A1 B1
:
AN BN
Outputs
Print the maximum possible sum of utilities of purchased integers.
Sample Input 1
Copy
3 5
3 3
4 4
2 5
Sample Output 1
Copy
8
Buy 2 and 3 to achieve the maximum possible total utility, 8.
Sample Input 2
Copy
3 6
3 3
4 4
2 5
Sample Output 2
Copy
9
Buy 2 and 4 to achieve the maximum possible total utility, 9.
Sample Input 3
Copy
7 14
10 5
7 4
11 4
9 8
3 6
6 2
8 9
Sample Output 3
Copy
32
#include<bits/stdc++.h>using namespace std;typedef long long LL;const int MAXN=1e5+5;int a[MAXN];LL b[MAXN];int main(){ int n,k; while(scanf("%d%d",&n,&k)!=EOF) { for(int i=1;i<=n;i++) scanf("%d%lld",&a[i],&b[i]); LL ans=0,sum=0; int tmp=k; tmp^=((1<<30)-1); for(int i=1;i<=n;i++) { if((tmp&a[i])==0) sum+=b[i]; } ans=max(ans,sum); for(int bit=0;bit<=30;bit++) { sum=0; tmp=k; if(tmp&(1<<bit)) { tmp^=(1<<bit); tmp|=((1<<bit)-1); tmp^=((1<<30)-1); for(int i=1;i<=n;i++) { if((tmp&a[i])==0) sum+=b[i]; } ans=max(ans,sum); } } printf("%lld\n",ans); } return 0;}
- Tenka1 Programmer Contest-D
- AtCoder. Tenka1 Programmer Contest C,D
- Tenka1 Programmer Contest
- AtCoder Tenka1 Programmer Beginner Contest D IntegerotS 数学
- Atcoder Tenka1 Programmer Beginner Contest IntegerotS 【异或+思维】
- 【Tenka1 Programmer Contest 2017 F】ModularPowerEquation!!(欧拉定理)
- English Contest -- The Programmer's Dream
- Contest - Problem D
- Contest 798 C&&D
- 1-6. Application R&D Programmer
- Belarusian State University & Kazakhstan Contest D Contest
- Programmer
- SDKD Summer Team Contest D
- Codeforces 725D Contest Balloons
- codeforces 725D Contest Balloons
- AtCoder Regular Contest 069 D
- codeforces contest 779 D题
- Atcoder Grand Contest 013D
- 字符设备实现原理
- BZOJ4384: [POI2015]Trzy wieże
- Java中的内存泄漏
- 【Angular-数据绑定】
- Windows下配置Apache+Tomcat WEB服务器
- Tenka1 Programmer Contest-D
- 利用SSH公钥实现A机器到B机器免密码登录
- HDU 2295 Radar(二分+DLX重复覆盖)
- c++项目--集合的并差交综合运算
- HTML基础
- 本周互动留言抽奖结果公布!!
- java代码块总结
- 区块宝周报:区块链一周大事排行榜0930
- RANSAC估计——以直线拟合为例