A
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
int f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
int main(){
//freopen("/Users/chutong/ACM/data.in","r",stdin);
//freopen("/Users/chutong/ACM/data.out","w",stdout);
int a[10];
a[1] = read();
a[2] = read();
a[3] = read();
a[4] = read();
LL sum = (LL)a[1] + a[2] + a[3] + a[4];
for(int i=1; i<=4; i++){
if (2*a[i] == sum){
cout << "YES" << endl;
return 0;
}
for(int j=1; j<=4; j++){
if (i != j && 2*(a[i] + a[j]) == sum){
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
B:
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
int f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 1e6 + 10;
int main(){
//freopen("/Users/chutong/ACM/data.in","r",stdin);
//freopen("/Users/chutong/ACM/data.out","w",stdout);
int n = read(),k = read();
string s;
cin >> s;
if (n == 1 && k > 0){
cout << 0 << endl;
return 0;
}
int tag = 0;
if (s[0] != '1' && k > 0){
s[0] = '1';
k--;
tag = 1;
}
for(int i=1; i<n; i++){
if (s[i] != '0' && k > 0){
s[i] = '0';
k--;
if (k == 0) break;
}
}
cout << s << endl;
return 0;
}
C
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef unsigned long long ULL;
LL Gcd(LL a, LL b){if (b == 0) return a; return Gcd(b , a%b);}
LL Lcm(LL a, LL b){ return a/Gcd(a,b)*b;}
inline int read(){
int f = 1, x = 0;char ch = getchar();
while (ch > '9' || ch < '0'){if (ch == '-')f = -f;ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0';ch = getchar();}
return x * f;
}
const int maxn = 8;
int n,m;
struct node
{
int u,v;
}p[maxn*maxn];
int id[maxn];
int mp[maxn][maxn];
int ans;
void dfs(int step){
if (step == n + 1){
memset(mp,0,sizeof(mp));
int res = 0;
// cout << step << ' ' << n << endl;
// for(int i=1; i<=n; i++){
// cout << id[i] << ' ';
// }
// cout << endl;
for(int i=1; i<=m; i++){
if (!mp[id[p[i].u]][id[p[i].v]]){
mp[id[p[i].u]][id[p[i].v]] = mp[id[p[i].v]][id[p[i].u]] = 1;
// cout << id[p[i].u] << ' ' << id[p[i].v] << endl;
res++;
}
}
ans = max(ans,res);
return;
}
for(int i=1; i<=6; i++){
id[step] = i;
dfs(step+1);
}
}
int main(){
//freopen("/Users/chutong/ACM/data.in","r",stdin);
//freopen("/Users/chutong/ACM/data.out","w",stdout);
n = read(),m = read();
for(int i=1; i<=m; i++){
p[i].u = read();
p[i].v = read();
}
dfs(1);
cout << ans << endl;
return 0;
}
D
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
const int maxn = 1e5 + 10;
long long a[maxn];
int used[maxn],b[maxn];
map<long long,int> mp;
vector<long long> v;
int main(){
int n;
scanf("%d",&n);
for(int i=1; i<=n; i++){
scanf("%lld",&a[i]);
mp[a[i]]++;
}
long long ans = 0;
for(int i=1; i<=n; i++){
scanf("%d",&b[i]);
if (mp[a[i]] >= 2){
ans += b[i];
used[i] = 1;
v.push_back(a[i]);
}
}
for(int i=1; i<=n; i++){
if (!used[i]){
for(auto now : v){
if (a[i] < now && ((a[i] | now) == now)){
ans += b[i];
break;
}
}
}
}
printf("%lld\n",ans);
return 0;
}