D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )

Marcin is a coach in his university. There are nn students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other.

Let‘s focus on the students. They are indexed with integers from 11 to nn. Each of them can be described with two integers aiai and bibi; bibi is equal to the skill level of the ii-th student (the higher, the better). Also, there are 6060 known algorithms, which are numbered with integers from 00 to 5959. If the ii-th student knows the jj-th algorithm, then the jj-th bit (2j2j) is set in the binary representation of aiai. Otherwise, this bit is not set.

Student xx thinks that he is better than student yy if and only if xx knows some algorithm which yy doesn‘t know. Note that two students can think that they are better than each other. A group of students can work together calmly if no student in this group thinks that he is better than everyone else in this group.

Marcin wants to send a group of at least two students which will work together calmly and will have the maximum possible sum of the skill levels. What is this sum?

Input

The first line contains one integer nn (1≤n≤70001≤n≤7000) — the number of students interested in the camp.

The second line contains nn integers. The ii-th of them is aiai (0≤ai<2600≤ai<260).

The third line contains nn integers. The ii-th of them is bibi (1≤bi≤1091≤bi≤109).

Output

Output one integer which denotes the maximum sum of bibi over the students in a group of students which can work together calmly. If no group of at least two students can work together calmly, print 0.

Examples

input

Copy

4
3 2 3 6
2 8 5 10

output

Copy

15

input

Copy

3
1 2 3
1 2 3

output

Copy

0

input

Copy

1
0
1

output

Copy

0

Note

In the first sample test, it‘s optimal to send the first, the second and the third student to the camp. It‘s also possible to send only the first and the third student, but they‘d have a lower sum of bibi.

In the second test, in each group of at least two students someone will always think that he is better than everyone else in the subset.

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <cmath>

//线段树
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r

#define gcd __gcd
#define mem(s,t) memset(s,t,sizeof(s))
#define debug(a,n) for(int i=0;i<n;i++) cout<<" "<<a[i];  cout<<endl;
#define Debug(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" ";   cout<<endl; }
#define rep(j,k) for (int i = j;   i < k;  i++)
#define per(j,k) for (int i = j-1; i >= k; i--)
#define input(a,k) for (int i = 1; i <= (int)(k); i++)  {scanf("%d",&a[i]) ; }
#define INPUT(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; }
#define TLE std::ios::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);   cout.precision(10);
    #define fi      first
    #define se      second
    #define pb      push_back
    #define pql     priority_queue<lli>
    #define pq      priority_queue<int>
    #define ok      return 0;
    #define oi(x)   cout<<x<<endl;
    #define os(str) cout<<string(str)<<endl;
using namespace std;
inline void No()  {    printf("NO\n"); }
inline void Yes() {    printf("YES\n");}

typedef long long lli;
typedef long double ld;

  const int  N         = 300002;
  const int  logN      = (int)log2(N)+1;
  const int  MOD7      = 1000000007;
  const lli  MOD9      = 998244353;
  const lli  MODL      = 1000000007;
  const int  INF       = 1000000007;
  const lli  INFL      = 4ll*1000000007ll*1000000007ll;
  const ld   PI        = acos(-1);
  const int  HPRIME    = 31;
  const ld   EPS       = 1e-10;
  typedef pair < int, int > pii;
  typedef pair < lli, lli > pll;
  typedef vector < lli > vl;
  typedef vector < int > vi;

int n;
lli ans;
struct node
{
    lli x,y;

}dp[7000+5],no;

int cmp(const node &a,const node &b)
{
    if(a.x!=b.x)   return a.x<b.x;
    return a.y<b.y;
}
bool vis[7000+5];
//#define LOCAL
lli AC(lli k)
{
    lli cnt = 0;
    for(int i=0;i<n;i++)
    {
        no = dp[i];
        if( (no.x|k) == k && !vis[i] )
        {
            cnt += no.y;
            vis[i] = true;
        }
    }
    return cnt;
}

int main()
{
    TLE;
#ifdef LOCAL
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    while(cin>>n)
    {
        mem(vis,0);   ans = 0;
        rep(0,n) cin>>dp[i].x;
        rep(0,n) cin>>dp[i].y;
        sort(dp,dp+n,cmp);
        for(int i=0;i<n-1;i++)
        {
            if(dp[i].x==dp[i+1].x)
            {
                if(!vis[i])
                {
                    ans += AC(dp[i].x);
                }
            }
        }
        cout<<ans<<endl;
    }
    ok;
}

 或者

struct node
{
    lli x,y;
    bool operator < (const node &now)const
    {
        if(x!=now.x)
            return x < now.x;
        return y<now.y;
    }
}dp[7000+5],no;

sort(dp,dp+n);

原文地址:https://www.cnblogs.com/Shallow-dream/p/11600188.html

时间: 2024-07-30 14:01:17

D. Marcin and Training Camp ( Codeforces Round #588 (Div. 2) )的相关文章

Codeforces Round #588 (Div. 2)

Codeforces Round #588 (Div. 2) A. Dawid and Bags of Candies 思路:水题 AC代码 #include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <sstr

Codeforces Round #588 (Div. 2) D. Marcin and Training Camp(思维)

链接: https://codeforces.com/contest/1230/problem/D 题意: Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. L

Codeforces Round #588 (Div. 2) C. Anadi and Domino(思维)

链接: https://codeforces.com/contest/1230/problem/C 题意: Anadi has a set of dominoes. Every domino has two parts, and each part contains some dots. For every a and b such that 1≤a≤b≤6, there is exactly one domino with a dots on one half and b dots on th

Codeforces Round #588 (Div. 2) E. Kamil and Making a Stream(DFS)

链接: https://codeforces.com/contest/1230/problem/E 题意: Kamil likes streaming the competitive programming videos. His MeTube channel has recently reached 100 million subscribers. In order to celebrate this, he posted a video with an interesting problem

A. Dawid and Bags of Candies ( Codeforces Round #588 (Div. 2) )

Dawid has four bags of candies. The ii-th of them contains aiai candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount o

B. Ania and Minimizing (Codeforces Round #588 (Div. 2) )

Ania has a large integer SS. Its decimal representation has length nn and doesn't contain any leading zeroes. Ania is allowed to change at most kk digits of SS. She wants to do it in such a way that SS still won't contain any leading zeroes and it'll

Codeforces Round #588 (Div. 1)

Contest Page 因为一些特殊的原因所以更得不是很及时-- A sol 不难发现当某个人diss其他所有人的时候就一定要被删掉. 维护一下每个人会diss多少个人,当diss的人数等于剩余人数$-1$的时候放队列里,每一次取队头更新其他人diss的人数. code B sol 一个结论:对于序列$a_1,a_2,...,a_n$,其前缀$gcd$数量不超过$log_2a_i$种.证明考虑从前往后计算前缀$gcd$,那么从第$i-1$个$gcd$到第$i$个$gcd$,数值要么不变要么至少

D. Marcin and Training Camp

题目链接:http://codeforces.com/contest/1230/problem/D D. Marcin and Training Camp time limit per test: 3 seconds memory limit per test: 256 megabytes input: standard input output: standard output 题目大意: 要组建一个小组,要求小组中每个人都不比所有人强,当一个人懂得一个算法但是另一个不懂那么前者认为他比后者强

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i