• 欢迎光临~

# A

``````#include<iostream>
#include<unordered_map>
using namespace std;
void solve()
{
int n;
cin >> n;
int sum1 = 0;
int sum2 = 2047;
for (int i = 0;i < n;i++)
{
int x;
cin >> x;
sum1 |= x;
sum2 &= x;
}
cout << sum1 - sum2 << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}

}
``````

# B

``````#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;

int n, k;
pair<int, int> a[N];
void solve()
{
int n, k;
cin >> n >> k;
for (int i = 0;i < n;i++)
cin >> a[i].second;
for (int i = 0;i < n;i++)
cin >> a[i].first;
int cur = 0;
int sum = 0;
sort(a, a + n);
while (k > 0 && cur < n)
{
sum += k;
while (k>0&&sum >= a[cur].second)
{
cur++;
}
if (cur < n)
{
k -= a[cur].first;
}
}
if (k > 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}

}
``````

# C

``````#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 200010;

int n, k;
LL a[N];
void solve()
{
int n;
cin >> n;
LL mx = -0x3f3f3f;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
mx = max(mx, a[i]);
}
if (n > 3)
{
cout << mx * n<<endl;
}
else if (n == 3)
{
LL t = 0;
t = max(t, a[1] * 3);
t = max(t, a[3] * 3);
t = max(t, abs(a[3] - a[1]) * 3);
t = max(t, abs(a[2] - a[1]) * 3);
t = max(t, abs(a[3] - a[2]) * 3);
t = max(t, a[1] + a[2] + a[3]);
cout << t << endl;
}
else if (n == 2)
cout << max(a[1] + a[2], abs(a[2] - a[1]) * 2) << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}

}
``````

# D

• 首先是个排列
• 满足先升序后降序，拐点的下标为 k(2≤k≤n−1)

``````#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <iomanip>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
int mod = 1e9 + 7;
const int N = 1e2+10;
int n, i, j, x, y;
int dp[N][N];
int check(int pos, int val)
{
if (pos == i && val != x)
return false;
if (pos == j && val != y)
return false;
else
return true;
}
void solve()
{
cin >> n >> i >> j >> x >> y;
memset(dp, 0, sizeof dp);
for (int i = 2;i <= n - 1;i++)
if (check(i, n))
dp[i][i] = 1;
for (int i = n;i >= 1;i--)
{
for (int j = i;j <= n;j++) {
int val = n - (j - i + 1);
if (check(i - 1, val))
(dp[i - 1][j] += dp[i][j]) %= mod;
if (check(j+1, val))
(dp[i][j + 1] += dp[i][j]) %= mod;
}
}
cout << dp[1][n] << endl;
}
int main()
{
int T;
cin >> T;
while (T--)
{
solve();
}

}
``````