Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7604ab9

Browse files
adds few good 1200-1300 questions
1 parent a2e6162 commit 7604ab9

File tree

4 files changed

+580
-0
lines changed

4 files changed

+580
-0
lines changed

‎solutions_codForces/333773467_863_B.cpp

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// Type definitions
5+
typedef long long ll;
6+
typedef pair<int, int> pii;
7+
typedef pair<ll, ll> pll;
8+
typedef vector<int> vi;
9+
typedef vector<ll> vl;
10+
typedef vector<pii> vpii;
11+
typedef vector<pll> vpll;
12+
typedef vector<vi> vvi;
13+
typedef vector<vl> vvl;
14+
15+
// Macros
16+
#define nline "\n"
17+
#define all(x) (x).begin(), (x).end()
18+
#define rall(x) (x).rbegin(), (x).rend()
19+
#define sz(x) (int)(x).size()
20+
#define pb push_back
21+
#define mp make_pair
22+
#define F first
23+
#define S second
24+
#define forn(i, n) for (int i = 0; i < int(n); i++)
25+
#define forr(i, a, b) for (int i = a; i <= b; i++)
26+
#define ford(i, a, b) for (int i = a; i >= b; i--)
27+
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
28+
29+
// clang-format off
30+
// Debug macros
31+
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
32+
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
33+
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
34+
35+
// Debug template functions
36+
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
37+
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
38+
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
39+
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
40+
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
41+
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
42+
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
43+
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
44+
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
45+
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
46+
// clang-format on
47+
48+
// Constants
49+
const int MOD = 1e9 + 7;
50+
const ll INF = 1e18;
51+
const double EPS = 1e-9;
52+
const double PI = acos(-1);
53+
54+
// Utility functions
55+
ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
56+
ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
57+
ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }
58+
ll mod_pow(ll base, ll exp, ll m = MOD)
59+
{
60+
ll res = 1;
61+
base %= m;
62+
while (exp > 0)
63+
{
64+
if (exp & 1)
65+
res = mod_mul(res, base, m);
66+
base = mod_mul(base, base, m);
67+
exp >>= 1;
68+
}
69+
return res;
70+
}
71+
ll mod_inv(ll a, ll m = MOD)
72+
{
73+
return mod_pow(a, m - 2, m); // Only works if m is prime
74+
}
75+
ll mod_div(ll a, ll b, ll m = MOD)
76+
{
77+
return mod_mul(a, mod_inv(b, m), m);
78+
}
79+
80+
ll binpow(ll base, ll exp, ll mod = MOD)
81+
{
82+
ll res = 1;
83+
base %= mod;
84+
while (exp > 0)
85+
{
86+
if (exp & 1)
87+
res = (res * base) % mod;
88+
base = (base * base) % mod;
89+
exp >>= 1;
90+
}
91+
return res;
92+
}
93+
/************/
94+
void solve()
95+
{
96+
int n;
97+
cin >> n;
98+
99+
n = (n << 1);
100+
101+
vi arr(n);
102+
103+
for (auto &i : arr)
104+
cin >> i;
105+
106+
int res = 1e9;
107+
for (int i = 0; i < n - 1; i++)
108+
{
109+
110+
for (int j = i + 1; j < n; j++)
111+
{
112+
113+
vector<int> v;
114+
for (int k = 0; k < n; k++)
115+
if (i != k && j != k)
116+
v.push_back(arr[k]);
117+
118+
sort(all(v));
119+
120+
int sum = 0;
121+
for (int k = 0; k < v.size() - 1; k += 2)
122+
{
123+
sum += abs(v[k + 1] - v[k]);
124+
}
125+
res = min(res, sum);
126+
}
127+
}
128+
129+
cout << res << nline;
130+
}
131+
int main()
132+
{
133+
ios_base::sync_with_stdio(0);
134+
cin.tie(0);
135+
cout.tie(0);
136+
#ifndef ONLINE_JUDGE
137+
freopen("./outputs/input.txt", "r", stdin);
138+
freopen("./outputs/output.txt", "w", stdout);
139+
cerr.rdbuf(cout.rdbuf());
140+
#endif
141+
142+
// int t;
143+
// cin >> t;
144+
// while (t--)
145+
solve();
146+
return 0;
147+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
// Type definitions
5+
typedef long long ll;
6+
typedef pair<int, int> pii;
7+
typedef pair<ll, ll> pll;
8+
typedef vector<int> vi;
9+
typedef vector<ll> vl;
10+
typedef vector<pii> vpii;
11+
typedef vector<pll> vpll;
12+
typedef vector<vi> vvi;
13+
typedef vector<vl> vvl;
14+
15+
// Macros
16+
#define nline "\n"
17+
#define all(x) (x).begin(), (x).end()
18+
#define rall(x) (x).rbegin(), (x).rend()
19+
#define sz(x) (int)(x).size()
20+
#define pb push_back
21+
#define mp make_pair
22+
#define F first
23+
#define S second
24+
#define forn(i, n) for (int i = 0; i < int(n); i++)
25+
#define forr(i, a, b) for (int i = a; i <= b; i++)
26+
#define ford(i, a, b) for (int i = a; i >= b; i--)
27+
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
28+
29+
// clang-format off
30+
// Debug macros
31+
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
32+
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
33+
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
34+
35+
// Debug template functions
36+
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
37+
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
38+
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
39+
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
40+
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
41+
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
42+
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
43+
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
44+
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
45+
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
46+
// clang-format on
47+
48+
// Constants
49+
const int MOD = 1e9 + 7;
50+
const ll INF = 1e18;
51+
const double EPS = 1e-9;
52+
const double PI = acos(-1);
53+
54+
// Utility functions
55+
ll mod_add(ll a, ll b, ll m = MOD) { return ((a % m) + (b % m)) % m; }
56+
ll mod_sub(ll a, ll b, ll m = MOD) { return ((a % m) - (b % m) + m) % m; }
57+
ll mod_mul(ll a, ll b, ll m = MOD) { return ((a % m) * (b % m)) % m; }
58+
ll mod_pow(ll base, ll exp, ll m = MOD)
59+
{
60+
ll res = 1;
61+
base %= m;
62+
while (exp > 0)
63+
{
64+
if (exp & 1)
65+
res = mod_mul(res, base, m);
66+
base = mod_mul(base, base, m);
67+
exp >>= 1;
68+
}
69+
return res;
70+
}
71+
ll mod_inv(ll a, ll m = MOD)
72+
{
73+
return mod_pow(a, m - 2, m); // Only works if m is prime
74+
}
75+
ll mod_div(ll a, ll b, ll m = MOD)
76+
{
77+
return mod_mul(a, mod_inv(b, m), m);
78+
}
79+
80+
ll binpow(ll base, ll exp, ll mod = MOD)
81+
{
82+
ll res = 1;
83+
base %= mod;
84+
while (exp > 0)
85+
{
86+
if (exp & 1)
87+
res = (res * base) % mod;
88+
base = (base * base) % mod;
89+
exp >>= 1;
90+
}
91+
return res;
92+
}
93+
/************/
94+
void solve()
95+
{
96+
ll n, k;
97+
98+
cin >> n >> k;
99+
100+
vpii arr(n);
101+
vi minimum(n);
102+
for (auto &i : arr)
103+
cin >> i.first;
104+
105+
for (auto &i : arr)
106+
cin >> i.second;
107+
108+
sort(all(arr));
109+
ford(i, n - 1, 0)
110+
{
111+
112+
minimum[i] = arr[i].second;
113+
if (i != (n - 1))
114+
minimum[i] = min(minimum[i], minimum[i + 1]);
115+
}
116+
117+
ll index = -1;
118+
ll res = k;
119+
ll attack = k;
120+
121+
while (1)
122+
{
123+
124+
auto it = upper_bound(all(arr), make_pair(res, INT_MAX), [](const pii &a, const pii &b)
125+
{ return a.first < b.first; });
126+
127+
index = it - arr.begin();
128+
if (index == n)
129+
{
130+
cout << "YES" << nline;
131+
return;
132+
}
133+
134+
attack -= minimum[index];
135+
if (attack <= 0)
136+
{
137+
cout << "NO" << nline;
138+
return;
139+
}
140+
res = res + attack;
141+
}
142+
}
143+
int main()
144+
{
145+
ios_base::sync_with_stdio(0);
146+
cin.tie(0);
147+
cout.tie(0);
148+
#ifndef ONLINE_JUDGE
149+
freopen("./outputs/input.txt", "r", stdin);
150+
freopen("./outputs/output.txt", "w", stdout);
151+
cerr.rdbuf(cout.rdbuf());
152+
#endif
153+
154+
int t;
155+
cin >> t;
156+
while (t--)
157+
solve();
158+
return 0;
159+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /