my.cpp
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 1e9 + 7;
int n, m;
bool check(vector<int> a, vector<int> b) {
for (int i = 0; i < n; i++) {
if (a[i] + b[i] >= 1 && a[i] + b[i] <= m) {
continue;
} else {
return false;
}
}
return true;
}
void solve() {
cin >> n >> m;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.begin(), a.end());
sort(b.begin(), b.end(), [](int& a, int& b) {
return a > b;
});
if (check(a, b)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T = 1;
cin >> T;
while (T--) {
solve();
}
return 0;
}
ac.cpp
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define out(x) cout << #x << '=' << (x) << endl
#define out2(x, y) cout << #x << '=' << (x) << ',' << #y << '=' << (y) << endl
#define no do { cout << "No" << endl; return; } while(0)
#define yes do { cout << "Yes" << endl; return; } while (0)
#define outvec(a) do { for (auto &v : (a)) { cout << v << ' '; } cout << endl; } while (0)
#define lowbit(x) ((x) & -(x))
#define gcd __gcd
#define inf 0x3f3f3f3f3f3f3f3fLL
#define infi 0x3f3f3f3f
using ll = long long;
using pii = pair<int, int>;
template<typename T> ostream & operator << (ostream &out,const set<T>&obj){out<<"set(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<*it;out<<")";return out;}
template<typename T1,typename T2> ostream & operator << (ostream &out,const map<T1,T2>&obj){out<<"map(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<it->first<<": "<<it->second;out<<")";return out;}
template<typename T1,typename T2> ostream & operator << (ostream &out,const pair<T1,T2>&obj){out<<"<"<<obj.first<<", "<<obj.second<<">";return out;}
template<typename T> ostream & operator << (ostream &out,const vector<T>&obj){out<<"vector(";for(auto it=obj.begin();it!=obj.end();it++) out<<(it==obj.begin()?"":", ")<<*it;out<<")";return out;}
const int MAX = (1ll << 31) - 1;
struct Edge{
int to;
int dis;
int next;
} edges[600000];
int cur[10010], head[10010], edge_num = -1;
int n, m, s, t;
void addEdge2(int from, int to, int dis){
edges[++edge_num].to = to;
edges[edge_num].dis = dis;
edges[edge_num].next = head[from];
head[from] = edge_num;
}
void addEdge(int from, int to, int dis){
addEdge2(from, to, dis), addEdge2(to, from, 0);
}
int d[10010];
int DFS(int u, int flow){
if (u == t) return flow;
int _flow = 0, __flow;
for (int& c_e = cur[u]; c_e != -1; c_e = edges[c_e].next){
int v = edges[c_e].to;
if (d[v] == d[u] + 1 && edges[c_e].dis > 0){
__flow = DFS(v, min(flow, edges[c_e].dis));
flow -= __flow;
edges[c_e].dis -= __flow;
_flow += __flow;
edges[c_e^1].dis += __flow;
if (!flow)
break;
}
}
if (!_flow) d[u] = -1;
return _flow;
}
bool BFS(){
memset(d, -1, sizeof(d));
queue<int> que; que.push(s);
d[s] = 0; int u, _new;
while (!que.empty()){
u = que.front(), que.pop();
for (int c_e = head[u]; c_e != -1; c_e = edges[c_e].next){
_new = edges[c_e].to;
if (d[_new] == -1 && edges[c_e].dis > 0){
d[_new] = d[u] + 1;
que.push(_new);
}
}
}
return (d[t] != -1);
}
int dinic(){
int max_flow = 0;
while (BFS()){
for (int i = 1; i <= n; ++i) cur[i] = head[i];
max_flow += DFS(s, MAX);
}
return max_flow;
}
void solve() {
memset(head, -1, sizeof(head));
edge_num = -1;
n = m = 0;
int x, y;
cin >> x >> y;
vector<int> a(x + 1), b(x + 1);
for (int i = 1; i <= x; i++) {
cin >> a[i];
}
for (int i = 1; i <= x; i++) {
cin >> b[i];
}
s = ++n, t = ++n;
for (int i = 1; i <= x; i++) {
n++;
addEdge(s, t + i, 1);
for (int j = 1; j <= x; j++) {
if (a[i] + b[j] > 0 && a[i] + b[j] <= y) {
addEdge(t + i, t + x + j, 1);
}
}
n++;
addEdge(t + x + i, t, 1);
}
if (dinic() == x) {
yes;
}
no;
}
int main(void) {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
}
data.cpp
#include<bits/stdc++.h>
#define int long long
using namespace std;
int Random(int mod) {
int ans = 2147483647;
return ans = ans * rand() % mod;
}
signed main()
{
struct _timeb T;
_ftime(&T);
srand(T.millitm);
int t = Random(30) + 1; // 1~30
cout << t << '\n';
while (t--) {
int n = Random(500) + 1, m = Random(500) + 1;
cout << n << ' ' << m << '\n';
for (int i = 0; i < n; i++) {
cout << Random(1001) - 500 << ' ';
}
for (int i = 0; i < n; i++) {
cout << Random(1001) - 500 << ' ';
}
cout << '\n';
}
return 0;
}
duipai.cpp
#include <iostream>
#include <cstdio>
#include <windows.h>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int ok = 0;
int n = 50;
for (int i = 1; i <= n; ++i)
{
system("data.exe > in.txt");
system("ac.exe < in.txt > ac.txt");
double begin = clock();
system("my.exe < in.txt > my.txt");
double end = clock();
double t = (end - begin);
if (system("fc ac.txt my.txt"))
{
printf("测试点#%d Wrong Answer\n", i);
return -1;
}
else if (t > 1000) //1秒
{
printf("测试点#%d Time Limited Exceeded 用时 %.0lfms\n", i, t);
}
else
{
printf("测试点#%d Accepted 用时%.0lfms\n", i, t);
ok++; //AC数量+1
}
printf("\n");
}
printf("\n");
double res = 100.0 * ok / n;
printf("共 %d 组测试数据,AC数据 %d 组。 得分%.1lf。", n, ok, res);
}