Skip to content

Commit 26b815a

Browse files
authored
Add files via upload
1 parent c0a4038 commit 26b815a

38 files changed

+2055
-0
lines changed

Sale.cpp

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// https://codeforces.com/contest/34/problem/B
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<long, long>
28+
#define vll vector<long long>
29+
#define inf 1e18
30+
#define gcd(a, b) __gcd(a, b)
31+
#define range(a,b) substr(a,b-a+1)
32+
#define fori(a, n) for (ll i = a; i < n; i++)
33+
#define forj(a, n) for (ll j = a; j < n; j++)
34+
#define fork(a, n) for (ll k = a; k < n; k++)
35+
#define print(x) for (auto i : x) {cout << i << " ";}
36+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
37+
38+
template <class T>
39+
bool comp(T a, T b) {
40+
if (a < b)
41+
return true;
42+
return false;
43+
}
44+
45+
int main()
46+
{
47+
FIO;
48+
49+
#ifndef ONLINE_JUDGE
50+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
51+
freopen("input.txt", "r", stdin);
52+
freopen("output.txt", "w", stdout);
53+
//freopen is used to associate a file with stdin or stdout stream in C++
54+
#endif
55+
56+
ll n, m, temp;
57+
cin >> n >> m;
58+
vll arr;
59+
fori(0, n) {
60+
cin >> temp;
61+
if (temp < 0)
62+
arr.pb(-temp);
63+
}
64+
sort(all(arr), greater<ll>());
65+
ll i = 0, ans = 0;
66+
while (i < m && i < arr.size())
67+
ans += arr[i++];
68+
cout << ans;
69+
return 0;
70+
}

Same Differences.cpp

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// https://codeforces.com/contest/1520/problem/D
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<long, long>
28+
#define vll vector<long long>
29+
#define inf 1e18
30+
#define gcd(a, b) __gcd(a, b)
31+
#define range(a,b) substr(a,b-a+1)
32+
#define fori(a, n) for (ll i = a; i < n; i++)
33+
#define forj(a, n) for (ll j = a; j < n; j++)
34+
#define fork(a, n) for (ll k = a; k < n; k++)
35+
#define print(x) for (auto i : x) {cout << i << " ";}
36+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
37+
38+
template <class T>
39+
bool comp(T a, T b) {
40+
if (a < b)
41+
return true;
42+
return false;
43+
}
44+
45+
int main()
46+
{
47+
FIO;
48+
49+
#ifndef ONLINE_JUDGE
50+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
51+
freopen("input.txt", "r", stdin);
52+
freopen("output.txt", "w", stdout);
53+
//freopen is used to associate a file with stdin or stdout stream in C++
54+
#endif
55+
56+
ll t;
57+
cin >> t;
58+
while (t--) {
59+
ll n;
60+
cin >> n;
61+
vll arr(n);
62+
map <ll, ll> ans;
63+
fori(0, n) {
64+
cin >> arr[i];
65+
if (ans.find(arr[i] - i - 1) != ans.end())
66+
ans[arr[i] - i - 1]++;
67+
else
68+
ans.insert({arr[i] - i - 1, 1});
69+
}
70+
ll gg = 0;
71+
for(auto i = ans.begin(); i != ans.end(); i++) {
72+
if (i->second >= 2)
73+
gg += (i -> second * (i -> second - 1)) / 2;
74+
}
75+
cout << gg << "\n";
76+
}
77+
78+
return 0;
79+
}

Santa Claus and Candies.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// https://codeforces.com/contest/753/problem/A
2+
#include <bits/stdc++.h>
3+
4+
#define fi first
5+
#define se second
6+
#define pb push_back
7+
#define mp make_pair
8+
#define ll long long
9+
#define pll pair<long, long>
10+
#define vll vector<long long>
11+
#define inf 1e18
12+
#define range(a,b) substr(a,b-a+1)
13+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
14+
15+
using namespace std;
16+
17+
int main()
18+
{
19+
FIO;
20+
21+
#ifndef ONLINE_JUDGE
22+
//remove this piece of code when this has to be submitted in kickstart
23+
freopen("input.txt", "r", stdin);
24+
freopen("output.txt", "w", stdout);
25+
//freopen is used to associate a file with stdin or stdout stream in C++
26+
#endif
27+
28+
ll n;
29+
cin >> n;
30+
ll i = 1;
31+
while ((i * (i + 1)) / 2 < n)
32+
i++;
33+
if ((i * (i + 1)) / 2 == n) {
34+
cout << i << "\n";
35+
for (ll j = 1; j <= i; j++)
36+
cout << j << " ";
37+
cout << "\n";
38+
}
39+
else if (n == 2)
40+
cout << 1 << "\n2\n";
41+
else {
42+
i--;
43+
cout << i << "\n";
44+
for (ll j = 1; j < i; j++)
45+
cout << j << " ";
46+
i--;
47+
cout << n - (i * (i + 1)) / 2;
48+
cout << "\n";
49+
}
50+
return 0;
51+
}

Soft Drinking.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// https://codeforces.com/contest/151/problem/A
2+
#include <iostream>
3+
#include <algorithm>
4+
#include <vector>
5+
6+
using namespace std;
7+
8+
bool comp(int a, int b)
9+
{
10+
return (a < b);
11+
}
12+
13+
int main()
14+
{
15+
int n, k, l, c, d, p, nl, np;
16+
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
17+
cout << (min({(k * l) / nl, (c * d), (p) / np}, comp)) / n;
18+
return 0;
19+
}

Soft Drinking.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
n, k, l, c, d, p, nl, np = map(int, input().split())
2+
print(min((k * l) // nl, (c * d), p // np) // n)

Soldier and Bananas.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// https://codeforces.com/problemset/problem/546/A
2+
#include <bits/stdc++.h>
3+
4+
#define fi first
5+
#define se second
6+
#define pb push_back
7+
#define mp make_pair
8+
#define ll long long
9+
#define pll pair<long, long>
10+
#define vll vector<long long>
11+
#define inf 1e18
12+
#define range(a,b) substr(a,b-a+1)
13+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
14+
15+
using namespace std;
16+
17+
int main()
18+
{
19+
FIO;
20+
21+
#ifndef ONLINE_JUDGE
22+
freopen("input.txt", "r", stdin);
23+
freopen("output.txt", "w", stdout);
24+
#endif
25+
26+
ll n, k, w;
27+
cin >> k >> n >> w;
28+
if ((ll)k * ((w * (w + 1)) / 2) <= n)
29+
cout << 0;
30+
else
31+
cout << (ll)k * ((w * (w + 1)) / 2) - (ll)n;
32+
33+
return 0;
34+
}

Special Permutation.cpp

+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// https://codeforces.com/contest/1612/problem/B
2+
/*
3+
4+
░██████╗██████╗░░█████╗░██████╗░░██████╗██╗░░██╗  ░██████╗░██╗░░░██╗██████╗░████████╗░█████╗░
5+
██╔════╝██╔══██╗██╔══██╗██╔══██╗██╔════╝██║░░██║  ██╔════╝░██║░░░██║██╔══██╗╚══██╔══╝██╔══██╗
6+
╚█████╗░██████╔╝███████║██████╔╝╚█████╗░███████║  ██║░░██╗░██║░░░██║██████╔╝░░░██║░░░███████║
7+
░╚═══██╗██╔═══╝░██╔══██║██╔══██╗░╚═══██╗██╔══██║  ██║░░╚██╗██║░░░██║██╔═══╝░░░░██║░░░██╔══██║
8+
██████╔╝██║░░░░░██║░░██║██║░░██║██████╔╝██║░░██║  ╚██████╔╝╚██████╔╝██║░░░░░░░░██║░░░██║░░██║
9+
╚═════╝░╚═╝░░░░░╚═╝░░╚═╝╚═╝░░╚═╝╚═════╝░╚═╝░░╚═╝  ░╚═════╝░░╚═════╝░╚═╝░░░░░░░░╚═╝░░░╚═╝░░╚═╝
10+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
11+
█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗█████╗
12+
╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝╚════╝
13+
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
14+
15+
*/
16+
17+
#include <bits/stdc++.h>
18+
19+
using namespace std;
20+
21+
#define fi first
22+
#define se second
23+
#define pb push_back
24+
#define mp make_pair
25+
#define all(x) x.begin(), x.end()
26+
#define ll long long
27+
#define pll pair<ll, ll>
28+
#define vll vector<long long>
29+
#define mll map<ll, ll>
30+
#define inf 1e18
31+
#define gcd(a, b) __gcd(a, b)
32+
#define range(a,b) substr(a,b-a+1)
33+
#define setbits(x) __builtin_popcountll(x)
34+
#define zrobits(x) __builtin_ctzll(x)
35+
#define fori(a, n) for (ll i = a; i < n; i++)
36+
#define forj(a, n) for (ll j = a; j < n; j++)
37+
#define fork(a, n) for (ll k = a; k < n; k++)
38+
#define print(x) for (auto i : x) {cout << i << " ";}
39+
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
40+
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
41+
42+
template <class T>
43+
bool comp(T a, T b) {
44+
if (a < b)
45+
return true;
46+
return false;
47+
}
48+
49+
int main()
50+
{
51+
FIO;
52+
53+
#ifndef ONLINE_JUDGE
54+
//remove this piece of code when this has to be submitted in kickstart, coding ninjas
55+
freopen("input.txt", "r", stdin);
56+
freopen("output.txt", "w", stdout);
57+
//freopen is used to associate a file with stdin or stdout stream in C++
58+
#endif
59+
60+
ll t;
61+
cin >> t;
62+
while (t--) {
63+
ll n, a, b;
64+
cin >> n >> a >> b;
65+
if ((a <= n / 2 && b <= n / 2) || (a > n / 2 && b > n / 2))
66+
cout << -1 << "\n";
67+
else if ((a > (n / 2) + 1) || (b < (n / 2)))
68+
cout << -1 << "\n";
69+
else {
70+
ll cnt = 1, t_n = n;
71+
cout << a << " ";
72+
while (cnt < n / 2) {
73+
if (t_n != b && t_n != a) {
74+
cout << t_n << " ";
75+
cnt++;
76+
}
77+
t_n--;
78+
}
79+
cnt = 1, t_n = 1;
80+
cout << b << " ";
81+
while (cnt < n / 2) {
82+
if (t_n != b && t_n != a) {
83+
cout << t_n << " ";
84+
cnt++;
85+
}
86+
t_n++;
87+
}
88+
cout << "\n";
89+
}
90+
}
91+
92+
return 0;
93+
}

Special Permutation.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
if n == 2:
4+
print(2, 1)
5+
else:
6+
for i in range(2, n + 1, 2):
7+
print(i, end=' ')
8+
if n % 2 != 0:
9+
print(n, end=' ')
10+
for i in range(1, n, 2):
11+
print(i, end=' ')
12+
print()

0 commit comments

Comments
 (0)