├── .vscode ├── base.cpp └── nptelcp.code-snippets ├── README.md ├── w1 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp ├── PPA_2.cpp ├── engineeringReverseSort.cpp ├── numberGame.cpp ├── reverseSort.cpp └── willItStop.cpp ├── w2 ├── PAA_1.cpp ├── PAA_2.cpp ├── PA_Q1.cpp └── PA_Q2.cpp ├── w3 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp ├── PPA_2.cpp ├── inland_war.cpp └── pancake_course.cpp ├── w4 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp ├── PPA_2.cpp └── unoin_find.cpp ├── w5 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp └── PPA_2.cpp ├── w6 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_Q1.cpp └── PPA_Q2.cpp ├── w7 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp └── PPA_2.cpp ├── w8 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp └── PPA_2.cpp └── w9 ├── PA_Q1.cpp ├── PA_Q2.cpp ├── PPA_1.cpp └── PPA_2.cpp /.vscode/base.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /.vscode/nptelcp.code-snippets: -------------------------------------------------------------------------------- 1 | { 2 | // Place your NPTEL Getting Started with Competitive Programming workspace snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and 3 | // description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope 4 | // is left empty or omitted, the snippet gets applied to all languages. The prefix is what is 5 | // used to trigger the snippet and the body will be expanded and inserted. Possible variables are: 6 | // $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. 7 | // Placeholders with the same ids are connected. 8 | // Example: 9 | "NPTEL": { 10 | "scope": "cpp,defaultText", 11 | "prefix": "nptel", 12 | "body": [ 13 | 14 | // Author : Kumar Akashdeep 15 | // Github : https://github.com/kadeep47 16 | 17 | // Problem : 18 | // Objective : 19 | 20 | // // Time Complexity : 21 | // // space Complexity : 22 | 23 | 24 | // #include 25 | // using namespace std; 26 | 27 | // #define int long long 28 | // #define ll long long 29 | // #define endl "\n" 30 | // #define st string 31 | // #define ld long double 32 | // #define pb push_back 33 | // #define vi vector 34 | // #define all(x) x.begin(), x.end() 35 | // #define rep(i, a, n) for (int i = a; i < n; ++i) 36 | // #define drep(i, a, n) for (int i = n; i > a; --i) 37 | // #define deb(x) cout<<#x< 43 | // ostream &operator<<(ostream &output, const vector &data) 44 | // { 45 | // for (const T &x : data) 46 | // { 47 | // output << x << " "; 48 | // } 49 | // return output; 50 | // } 51 | // template 52 | // istream &operator>>(istream &input, vector &data) 53 | // { 54 | // for (auto &item : data) 55 | // { 56 | // input >> item; 57 | // } 58 | // return input; 59 | // } 60 | // int setBits(int n) { return (__builtin_popcountll(n)); } 61 | // void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 62 | // void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 63 | // constexpr int MOD = 1e9 + 7, mod = 998244353; 64 | 65 | // const int N = 1e6 + 1; 66 | 67 | // void precompute() {} 68 | 69 | // void solve() 70 | // { 71 | // int cnt = 0; 72 | // int flag = 0; 73 | // int n; cin >> n; 74 | // vi v(n); cin >> v; 75 | // cout << cnt << endl; 76 | // } 77 | 78 | // int32_t main() 79 | // { 80 | // ios_base::sync_with_stdio(false); 81 | // cin.tie(NULL); 82 | // precompute(); 83 | // int T = 1; 84 | 85 | // // cin >> T; 86 | 87 | // for (int i = 1; i <= T; i++) 88 | // { 89 | // // cout << "Case #" << i << ": "; 90 | // solve(); 91 | // } 92 | // return 0; 93 | // } 94 | ], 95 | // "description": "NPTEL Course 7th sem " 96 | } 97 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Solutions for NPTEL Course : Getting Started with Competitive Programming 2 | ## Course URL : [Getting Started with Competitive Programming](https://onlinecourses.nptel.ac.in/noc23_cs103/course) 3 | 4 | 5 | 6 | CheckList : 7 | - [x] Week 1 8 | - [x] Week 2 9 | - [x] Week 3 10 | - [x] Week 4 11 | - [x] Week 5 12 | - [x] Week 6 13 | - [x] Week 7 14 | - [ ] Week 8 15 | - [ ] Week 9 16 | - [ ] Week 10 17 | - [ ] Week 11 18 | - [ ] Week 12 19 | -------------------------------------------------------------------------------- /w1/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | void solve() 57 | { 58 | int n, m; 59 | cin >> n >> m; 60 | vector y(n), d(m); 61 | int y1 = 0, d1 = 0; 62 | for (int i = 0; i < n; i++) 63 | { 64 | cin >> y[i]; 65 | y1 += y[i]; 66 | } 67 | for (int i = 0; i < m; i++) 68 | { 69 | cin >> d[i]; 70 | d1 += d[i]; 71 | } 72 | if (y1 > d1) 73 | { 74 | cout << "Yudhisthira" << endl; 75 | } 76 | else if (d1 == y1) 77 | cout << "Draw" << endl; 78 | else 79 | cout << "Duryodhana" << endl; 80 | } 81 | 82 | int32_t main() 83 | { 84 | ios_base::sync_with_stdio(false); 85 | cin.tie(NULL); 86 | precompute(); 87 | int T = 1; 88 | 89 | cin >> T; 90 | 91 | for (int i = 1; i <= T; i++) 92 | { 93 | // cout << "Case #" << i << ": "; 94 | solve(); 95 | } 96 | return 0; 97 | } -------------------------------------------------------------------------------- /w1/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define int long long 5 | 6 | void solve() 7 | { 8 | int m, n, s, x, temp; 9 | cin >> m >> n >> s >> x; 10 | 11 | int count = 2 * n + 2 * m - 4; 12 | vector a(count); 13 | 14 | for (int i = 0; i < m; i++) 15 | { 16 | for (int j = 0; j < n; j++) 17 | { 18 | if (i == 0) 19 | cin >> a[(j + s) % count]; 20 | else if (i == m - 1) 21 | cin >> a[(m + 2 * n - j - 3 + s) % count]; 22 | else if (j == 0) 23 | cin >> a[(2 * m + 2 * n - i - 4 + s) % count]; 24 | else if (j == n - 1) 25 | cin >> a[(n + i - 1 + s) % count]; 26 | else 27 | cin >> temp; 28 | } 29 | } 30 | 31 | for (int k = 0; k < count; k++) 32 | { 33 | int i, j; 34 | 35 | if (k <= n - 1) 36 | { 37 | i = 0; 38 | j = k; 39 | } 40 | else if (k <= n + m - 2) 41 | { 42 | i = k - n + 1; 43 | j = n - 1; 44 | } 45 | else if (k <= 2 * n + m - 3) 46 | { 47 | i = m - 1; 48 | j = m + 2 * n - k - 3; 49 | } 50 | else 51 | { 52 | i = 2 * m + 2 * n - k - 4; 53 | j = 0; 54 | } 55 | 56 | if ((i + j) % x == 0) 57 | cout << a[k] << " "; 58 | } 59 | 60 | cout << endl; 61 | } 62 | 63 | int32_t main() 64 | { 65 | solve(); 66 | return 0; 67 | } -------------------------------------------------------------------------------- /w1/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | priority_queue pq; 63 | int ans = 0; 64 | pq.push(n); 65 | while(pq.size() != n){ 66 | int top = pq.top(); pq.pop(); 67 | pq.push(top/2); 68 | pq.push(top - top/2); 69 | ans += (top/2) * (top-top/2); 70 | } 71 | 72 | cout << ans <> T; 83 | 84 | for (int i = 1; i <= T; i++) 85 | { 86 | // cout << "Case #" << i << ": "; 87 | solve(); 88 | } 89 | return 0; 90 | } -------------------------------------------------------------------------------- /w1/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | void solve() 57 | { 58 | int cnt = 0; 59 | int flag = 0; 60 | int n; 61 | cin >> n; 62 | // update is required as there is no k value 63 | // int k ; cin >> k; 64 | // if(n%k == 0) cout << "NO"; 65 | // else cout <<"YES"; 66 | 67 | // but in current condition 68 | if (n == 1) 69 | { 70 | cout << "YES"; 71 | } 72 | else 73 | { 74 | cout << "NO"; 75 | } 76 | cout << endl; 77 | } 78 | 79 | int32_t main() 80 | { 81 | ios_base::sync_with_stdio(false); 82 | cin.tie(NULL); 83 | precompute(); 84 | int T = 1; 85 | 86 | // cin >> T; 87 | 88 | for (int i = 1; i <= T; i++) 89 | { 90 | // cout << "Case #" << i << ": "; 91 | solve(); 92 | } 93 | return 0; 94 | } -------------------------------------------------------------------------------- /w1/engineeringReverseSort.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w1/numberGame.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w1/reverseSort.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | 58 | 59 | void reversort(vi v, int n){ 60 | int cost =0 ; 61 | 62 | for(int i =0 ;i> n; 77 | vi v(n); cin >> v; 78 | return reversort(v,n); 79 | } 80 | 81 | 82 | 83 | int32_t main() 84 | { 85 | ios_base::sync_with_stdio(false); 86 | cin.tie(NULL); 87 | precompute(); 88 | int T = 1; 89 | 90 | cin >> T; 91 | 92 | for (int i = 1; i <= T; i++) 93 | { 94 | cout << "Case #" << i << ": "; 95 | solve(); 96 | } 97 | return 0; 98 | } -------------------------------------------------------------------------------- /w1/willItStop.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w2/PAA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | bool flag = 0; 61 | int n; cin >> n; 62 | int d; cin >> d; 63 | vi v(2*n); cin >> v; 64 | 65 | sort(all(v)); 66 | 67 | int j = n; 68 | int i = 0; 69 | while(j <2*n){ 70 | if(d > v[j] - v[i]){ 71 | flag = 1; 72 | break; 73 | } 74 | i++; 75 | j++; 76 | } 77 | 78 | print(!flag); 79 | } 80 | 81 | int32_t main() 82 | { 83 | ios_base::sync_with_stdio(false); 84 | cin.tie(NULL); 85 | precompute(); 86 | int T = 1; 87 | 88 | cin >> T; 89 | 90 | for (int i = 1; i <= T; i++) 91 | { 92 | // cout << "Case #" << i << ": "; 93 | solve(); 94 | } 95 | return 0; 96 | } -------------------------------------------------------------------------------- /w2/PAA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | int que(int x,int sum , vi v,int n){ 57 | if(x>sum ) return -1; 58 | if(x== sum )return n; 59 | 60 | int crt = 0; 61 | int i =0 ; 62 | while(crt> n; 76 | int q; 77 | cin >> q; 78 | 79 | vi v(n); 80 | cin >> v; 81 | sort(all(v),greater()); 82 | 83 | int sum = accumulate(all(v),0); 84 | 85 | while (q--) 86 | { 87 | int x ; cin >> x; 88 | int ans = que(x,sum,v,n); 89 | cout << ans <> T; 103 | 104 | for (int i = 1; i <= T; i++) 105 | { 106 | // cout << "Case #" << i << ": "; 107 | solve(); 108 | } 109 | return 0; 110 | } -------------------------------------------------------------------------------- /w2/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | // cout << n <> T; 83 | 84 | for (int i = 1; i <= T; i++) 85 | { 86 | // cout << "Case #" << i << ": "; 87 | solve(); 88 | } 89 | return 0; 90 | } -------------------------------------------------------------------------------- /w2/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | // Author : Kumar Akashdeep 2 | // Github : https://github.com/kadeep47 3 | 4 | // Problem : 5 | // Objective : 6 | 7 | // Time Complexity : 8 | // space Complexity : 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define int long long 14 | #define ll long long 15 | #define endl "\n" 16 | #define st string 17 | #define ld long double 18 | #define pb push_back 19 | #define vi vector 20 | #define all(x) x.begin(), x.end() 21 | #define rep(i, a, n) for (int i = a; i < n; ++i) 22 | #define drep(i, a, n) for (int i = n; i > a; --i) 23 | #define deb(x) cout << #x << x << endl; 24 | 25 | #define PI 3.14159265359 26 | #define inf 9e18 27 | 28 | template 29 | ostream &operator<<(ostream &output, const vector &data) 30 | { 31 | for (const T &x : data) 32 | { 33 | output << x << " "; 34 | } 35 | return output; 36 | } 37 | template 38 | istream &operator>>(istream &input, vector &data) 39 | { 40 | for (auto &item : data) 41 | { 42 | input >> item; 43 | } 44 | return input; 45 | } 46 | int setBits(int n) { return (__builtin_popcountll(n)); } 47 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 48 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 49 | constexpr int MOD = 1e9 + 7, mod = 998244353; 50 | 51 | const int N = 1e6 + 1; 52 | 53 | void precompute() {} 54 | 55 | void solve() 56 | { 57 | 58 | int n, m; 59 | cin >> n >> m; 60 | 61 | int temp; 62 | vector A; 63 | for (int i = 0; i < n; i++) 64 | { 65 | cin >> temp; 66 | A.push_back(temp); 67 | } 68 | 69 | for (int i = 0; i < n; i += m) 70 | { 71 | if (A.begin() + i + m > A.end()) 72 | { 73 | sort(A.begin() + i, A.end()); 74 | } 75 | else 76 | { 77 | sort(A.begin() + i, A.begin() + i + m); 78 | } 79 | } 80 | 81 | for (int i = 0; i < A.size(); i++) 82 | { 83 | if (i != A.size() - 1) 84 | cout << A[i] << " "; 85 | else 86 | cout << A[i]; 87 | } 88 | } 89 | 90 | int32_t main() 91 | { 92 | ios_base::sync_with_stdio(false); 93 | cin.tie(NULL); 94 | precompute(); 95 | int T = 1; 96 | 97 | // cin >> T; 98 | 99 | for (int i = 1; i <= T; i++) 100 | { 101 | // cout << "Case #" << i << ": "; 102 | solve(); 103 | } 104 | return 0; 105 | } -------------------------------------------------------------------------------- /w3/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | bool powerOfTwo(int n) 57 | { 58 | if(n==0) 59 | return false; 60 | 61 | return (ceil(log2(n)) == floor(log2(n))); 62 | } 63 | 64 | 65 | void solve() 66 | { 67 | ll n, c = 0, ans = LONG_LONG_MAX; 68 | cin >> n; 69 | string sn; 70 | if (powerOfTwo(n) == true) 71 | cout << "0" <> T; 139 | 140 | for (int i = 1; i <= T; i++) 141 | { 142 | // cout << "Case #" << i << ": "; 143 | solve(); 144 | } 145 | return 0; 146 | } -------------------------------------------------------------------------------- /w3/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | struct ele 57 | { 58 | int val; 59 | int ind; 60 | int arr; 61 | 62 | ele(int val, int ind, int arr) 63 | : val(val), ind(ind), arr(arr) 64 | { 65 | } 66 | }; 67 | 68 | struct compareVal 69 | { 70 | bool operator()(ele const &a, ele const &b) 71 | { 72 | if (a.val == b.val) 73 | { 74 | if (a.ind == b.ind) 75 | { 76 | return a.arr < b.arr; 77 | } 78 | return a.ind < b.ind; 79 | } 80 | return a.val < b.val; 81 | } 82 | }; 83 | 84 | struct compareind 85 | { 86 | bool operator()(ele const &a, ele const &b) 87 | { 88 | if (a.ind == b.ind) 89 | { 90 | if (a.val == b.val) 91 | { 92 | return a.arr > b.arr; 93 | } 94 | return a.val > b.val; 95 | } 96 | return a.ind < b.ind; // smaller order of index matter's 97 | } 98 | }; 99 | 100 | bool cum(ele const &a, ele const &b) 101 | { 102 | if (a.val > b.val && a.ind < b.ind) 103 | { 104 | return true; 105 | } 106 | 107 | return false; 108 | } 109 | 110 | void solve() 111 | { 112 | int cnt = 0; 113 | int flag = 0; 114 | int n; 115 | cin >> n; 116 | int m, days; 117 | cin >> m >> days; 118 | 119 | vi v(n); 120 | cin >> v; 121 | vi vv(m); 122 | cin >> vv; 123 | 124 | // cout << v << endl; 125 | // cout << vv << endl; 126 | 127 | priority_queue, compareVal> pq; 128 | priority_queue, compareVal> pq2; 129 | priority_queue, compareind> ans; 130 | 131 | rep(i, 0, n) 132 | { 133 | pq.push(ele(v[i], i, 1)); 134 | } 135 | 136 | rep(i, 0, m) 137 | { 138 | pq.push(ele(vv[i], i, 2)); 139 | } 140 | 141 | int max2 = 0; 142 | int max1 = 0; 143 | 144 | while (!pq.empty()) 145 | { 146 | 147 | ele e = pq.top(); 148 | // cout << e.val << " " << e.ind << " " << e.arr << endl; 149 | 150 | if (e.arr == 1) 151 | { 152 | if (e.ind < max1) 153 | { 154 | pq2.push(e); 155 | } 156 | else 157 | { 158 | ans.push(e); 159 | max1 = e.ind; 160 | } 161 | } 162 | else 163 | { 164 | if (e.ind < max2) 165 | { 166 | pq2.push(e); 167 | } 168 | else 169 | { 170 | ans.push(e); 171 | max2 = e.ind; 172 | } 173 | } 174 | pq.pop(); 175 | if (ans.size() > days) 176 | ans.pop(); 177 | } 178 | // cout << "pq2" << endl; 179 | // while (!pq2.empty()) 180 | // { 181 | 182 | // ele e = pq2.top(); 183 | // cout << e.val << " " << e.ind << " " << e.arr << endl; 184 | // pq2.pop(); 185 | // } 186 | 187 | // cout << "asn" << endl; 188 | // while (!ans.empty()) 189 | // { 190 | 191 | // ele e = ans.top(); 192 | // cout << e.val << " " << e.ind << " " << e.arr << endl; 193 | // ans.pop(); 194 | // } 195 | 196 | if (ans.size() < days) 197 | { 198 | int diff = days - ans.size(); 199 | while (diff--) 200 | { 201 | ans.push(pq2.top()); 202 | if (ans.size() > days) 203 | ans.pop(); 204 | pq2.pop(); 205 | } 206 | } 207 | 208 | // cout << days << endl; 209 | 210 | vector va; 211 | vector vb; 212 | 213 | while (!ans.empty()) 214 | { 215 | ele e = ans.top(); 216 | // cout << e.val << " "; 217 | // cout << e.ind << " " << e.arr << endl; 218 | if (e.arr == 1) 219 | va.push_back(e); 220 | else 221 | vb.push_back(e); 222 | ans.pop(); 223 | } 224 | 225 | vector fin; 226 | 227 | int i = 0, j = 0; 228 | while (i < va.size() && j < vb.size()) 229 | { 230 | ele ea = va[i]; 231 | ele eb = vb[j]; 232 | if (ea.val < eb.val) 233 | { 234 | fin.push_back(ea.val); 235 | i++; 236 | }else if (ea.val == eb.val){ 237 | int tempi = i; 238 | int tempj = j; 239 | ele base1 = va[i]; 240 | ele base2 = vb[j]; 241 | while(base1.val == base2.val){ 242 | fin.push_back(base1.val); 243 | tempi++; 244 | tempj++; 245 | base1 = va[tempi]; 246 | base2 = vb[tempj]; 247 | } 248 | if(base1.val > base2.val){ 249 | i = tempi; 250 | }else{ 251 | j = tempj; 252 | } 253 | } 254 | else 255 | { 256 | fin.push_back(eb.val); 257 | j++; 258 | } 259 | } 260 | 261 | while (i < va.size()) 262 | { 263 | ele ea = va[i]; 264 | fin.push_back(ea.val); 265 | i++; 266 | } 267 | 268 | while (j < vb.size()) 269 | { 270 | ele eb = vb[j]; 271 | fin.push_back(eb.val); 272 | j++; 273 | } 274 | 275 | reverse(all(fin)); 276 | 277 | cout << fin << endl; 278 | } 279 | 280 | int32_t main() 281 | { 282 | ios_base::sync_with_stdio(false); 283 | cin.tie(NULL); 284 | precompute(); 285 | int T = 1; 286 | 287 | // cin >> T; 288 | 289 | for (int i = 1; i <= T; i++) 290 | { 291 | // cout << "Case #" << i << ": "; 292 | solve(); 293 | } 294 | return 0; 295 | } -------------------------------------------------------------------------------- /w3/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | void solve() 57 | { 58 | int cnt = 0; 59 | int flag = 0; 60 | int n; 61 | cin >> n; 62 | int q ;cin >> q; 63 | vi v(n); 64 | cin >> v; 65 | 66 | 67 | 68 | // cout << n << " -- "<< q<< " -- " << v<>a >> b; 72 | // cout << a<< " " << b << " "; 73 | auto it = find(v.rbegin(),v.rend(),b); 74 | if(it != v.rend()){ 75 | auto itt = find(it,v.rend(),a); 76 | if(itt != v.rend()){ 77 | cnt++; 78 | } 79 | } 80 | } 81 | 82 | cout << cnt << endl; 83 | } 84 | 85 | int32_t main() 86 | { 87 | ios_base::sync_with_stdio(false); 88 | cin.tie(NULL); 89 | precompute(); 90 | int T = 1; 91 | 92 | cin >> T; 93 | 94 | for (int i = 1; i <= T; i++) 95 | { 96 | // cout << "Case #" << i << ": "; 97 | solve(); 98 | } 99 | return 0; 100 | } -------------------------------------------------------------------------------- /w3/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | void ankita(vi v, vi vv) 57 | { 58 | 59 | int crt = v[0]; 60 | int i = 1; 61 | while (true) 62 | { 63 | cout << crt << " "; 64 | if (i % 2) 65 | { 66 | auto itvv = upper_bound(all(vv), crt); 67 | if (itvv == vv.end()) 68 | { 69 | cout << "Ankita" << endl; 70 | return; 71 | } 72 | else 73 | { 74 | crt = vv[itvv - vv.begin()]; 75 | } 76 | } 77 | else 78 | { 79 | auto itv = upper_bound(all(v), crt); 80 | if (itv == v.end()) 81 | { 82 | cout << "Biswas" << endl; 83 | return; 84 | } 85 | else 86 | { 87 | crt = v[itv - v.begin()]; 88 | } 89 | } 90 | } 91 | } 92 | 93 | void biswas(vi v, vi vv) 94 | { 95 | // same as ankita fxn 96 | } 97 | 98 | void solve() 99 | { 100 | int cnt = 0; 101 | int flag = 0; 102 | 103 | int n; 104 | cin >> n; 105 | vi v(n); 106 | cin >> v; 107 | 108 | int m; 109 | cin >> m; 110 | vi vv(m); 111 | cin >> vv; 112 | 113 | sort(all(v)); 114 | sort(all(vv)); 115 | 116 | if (v[n - 1] < vv[m - 1]) 117 | { 118 | cout << "Biswas"; 119 | } 120 | else 121 | { 122 | cout << "Ankita"; 123 | } 124 | cout << endl; 125 | 126 | if (vv[m - 1] < v[n - 1]) 127 | { 128 | cout << "Ankita"; 129 | } 130 | else 131 | { 132 | cout << "Biswas"; 133 | } 134 | cout << endl; 135 | 136 | } 137 | 138 | int32_t main() 139 | { 140 | ios_base::sync_with_stdio(false); 141 | cin.tie(NULL); 142 | precompute(); 143 | int T = 1; 144 | 145 | cin >> T; 146 | 147 | for (int i = 1; i <= T; i++) 148 | { 149 | // cout << "Case #" << i << ": "; 150 | solve(); 151 | } 152 | return 0; 153 | } -------------------------------------------------------------------------------- /w3/inland_war.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | bool comp(const pair &a, const pair &b) 9 | { 10 | return a.second < b.second; 11 | } 12 | int main() 13 | { 14 | int n, m; 15 | 16 | cin >> n >> m; 17 | vector> requests; 18 | 19 | for (int i = 0; i < m; i++) 20 | { 21 | int a, b; 22 | cin >> a >> b; 23 | requests.push_back(make_pair(a, b)); 24 | } 25 | 26 | sort(requests.begin(), requests.end(), comp); 27 | 28 | int ans = 0; 29 | int lastbridge = -1; 30 | 31 | for (auto request : requests) 32 | { 33 | 34 | if (lastbridge > request.first) 35 | continue; 36 | else 37 | { 38 | 39 | lastbridge = request.second; 40 | ans++; 41 | } 42 | } 43 | cout << ans << endl; 44 | return 0; 45 | } -------------------------------------------------------------------------------- /w3/pancake_course.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | using namespace std; 8 | 9 | void testcase(int t) 10 | { 11 | // s is the string encoding the input state of pancake 12 | //+ for happy and - for blank 13 | string s; 14 | // size of pancake flipper(oversized) 15 | int k; 16 | cin >> s; 17 | cin >> k; 18 | 19 | int n = s.size(); // number of pancakes 20 | 21 | vector obsolete_flips(n + 1); 22 | for (int i = 0; i <= n; i++) 23 | { 24 | obsolete_flips[i] = 0; 25 | } 26 | 27 | int answer = 0, flipped; 28 | for (int j = 0; j < n - k + 1; j++) 29 | { 30 | char state = s[j]; 31 | // incorporate instructionos that we have so far by just adding the value from the previous cell 32 | obsolete_flips[j] += obsolete_flips[j - 1]; 33 | // count how many times the jth pancake does in fact get flipped 34 | flipped = answer - obsolete_flips[j]; 35 | // figure out if a flip need to happen here 36 | bool original_destroyed = (state == '+' and flipped % 2 == 1); 37 | bool blank_not_fixed = (state == '-' and flipped % 2 == 0); 38 | 39 | if (original_destroyed or blank_not_fixed) //-> (plain side with even flips) or (happy side with odd flips) 40 | { 41 | // if flip need to happen 42 | // increment the answer 43 | answer++; 44 | // make it obsolete k steps later 45 | if (j < n - k + 1) 46 | obsolete_flips[j + k] += 1; 47 | } 48 | } 49 | 50 | // checking remaining pancakes 51 | for (int j = n - k + 1; j <= n; j++) 52 | { 53 | // similar to what happen before ! 54 | 55 | obsolete_flips[j] += obsolete_flips[j - 1]; 56 | flipped = answer - obsolete_flips[j]; 57 | char state = s[j]; 58 | 59 | bool original_destroyed = (state == '+' and flipped % 2 == 1); 60 | bool blank_not_fixed = (state == '-' and flipped % 2 == 0); 61 | // if something is not right it cannot be fixed anymore , print the impossible as answer 62 | if (original_destroyed or blank_not_fixed) 63 | { 64 | cout << "Case #" << t << ": IMPOSSIBLE" << endl; 65 | return; 66 | } 67 | } 68 | // if all k-1 pancakes at happy side print the number of flips you have to made to make all pancakes happyside(+) 69 | cout << "Case #" << t << ": " << answer << endl; 70 | } 71 | signed main() 72 | { 73 | // processing testcases 74 | int t =77 ; 75 | testcase(77); 76 | 77 | return 0; 78 | } -------------------------------------------------------------------------------- /w4/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | // Author : Kumar Akashdeep 2 | // Github : https://github.com/kadeep47 3 | 4 | // Problem : 5 | // Objective : 6 | 7 | // Time Complexity : 8 | // space Complexity : 9 | 10 | #include 11 | using namespace std; 12 | 13 | #define int long long 14 | #define ll long long 15 | #define endl "\n" 16 | #define st string 17 | #define ld long double 18 | #define pb push_back 19 | #define vi vector 20 | #define all(x) x.begin(), x.end() 21 | #define rep(i, a, n) for (int i = a; i < n; ++i) 22 | #define drep(i, a, n) for (int i = n; i > a; --i) 23 | #define deb(x) cout << #x << x << endl; 24 | 25 | #define PI 3.14159265359 26 | #define inf 9e18 27 | 28 | template 29 | ostream &operator<<(ostream &output, const vector &data) 30 | { 31 | for (const T &x : data) 32 | { 33 | output << x << " "; 34 | } 35 | return output; 36 | } 37 | template 38 | istream &operator>>(istream &input, vector &data) 39 | { 40 | for (auto &item : data) 41 | { 42 | input >> item; 43 | } 44 | return input; 45 | } 46 | int setBits(int n) { return (__builtin_popcountll(n)); } 47 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 48 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 49 | constexpr int MOD = 1e9 + 7, mod = 998244353; 50 | 51 | const int N = 1e6 + 1; 52 | 53 | void precompute() {} 54 | 55 | void solve() 56 | { 57 | int n; 58 | cin >> n; 59 | 60 | vector> a(n, vector(2)); 61 | 62 | for (int i = 0; i < n; i++) 63 | cin >> a[i][0] >> a[i][1]; 64 | 65 | map m; 66 | set left; 67 | set right; 68 | vector res(n); 69 | 70 | for (int i = 0; i < n; i++) 71 | { 72 | if (a[i][0] == 0) 73 | res[1] = a[i][1]; 74 | 75 | m[a[i][0]] = a[i][1]; 76 | 77 | auto j = right.find(a[i][0]); 78 | 79 | if (j == right.end()) 80 | left.insert(a[i][0]); 81 | else 82 | right.erase(j); 83 | 84 | auto k = left.find(a[i][1]); 85 | 86 | if (k == left.end()) 87 | right.insert(a[i][1]); 88 | else 89 | left.erase(k); 90 | } 91 | 92 | res[0] = *(left.begin()); 93 | 94 | for (int i = 0; i < n - 2; i++) 95 | { 96 | res[i + 2] = m[res[i]]; 97 | } 98 | 99 | for (int i = 0; i < n; i++) 100 | { 101 | cout << res[i] << " "; 102 | } 103 | 104 | cout << endl; 105 | } 106 | 107 | int32_t main() 108 | { 109 | ios_base::sync_with_stdio(false); 110 | cin.tie(NULL); 111 | precompute(); 112 | int T = 1; 113 | 114 | // cin >> T; 115 | 116 | for (int i = 1; i <= T; i++) 117 | { 118 | // cout << "Case #" << i << ": "; 119 | solve(); 120 | } 121 | return 0; 122 | } 123 | -------------------------------------------------------------------------------- /w4/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | using namespace std; 5 | 6 | #define int long long 7 | #define ll long long 8 | #define endl "\n" 9 | #define st string 10 | #define ld long double 11 | #define pb push_back 12 | #define vi vector 13 | #define all(x) x.begin(), x.end() 14 | #define rep(i, a, n) for (int i = a; i < n; ++i) 15 | #define drep(i, a, n) for (int i = n; i > a; --i) 16 | #define deb(x) cout << #x << x << endl; 17 | 18 | #define PI 3.14159265359 19 | #define inf 9e18 20 | 21 | template 22 | ostream &operator<<(ostream &output, const vector &data) 23 | { 24 | for (const T &x : data) 25 | { 26 | output << x << " "; 27 | } 28 | return output; 29 | } 30 | template 31 | istream &operator>>(istream &input, vector &data) 32 | { 33 | for (auto &item : data) 34 | { 35 | input >> item; 36 | } 37 | return input; 38 | } 39 | int setBits(int n) { return (__builtin_popcountll(n)); } 40 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 41 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 42 | constexpr int MOD = 1e9 + 7, mod = 998244353; 43 | 44 | const int N = 1e6 + 1; 45 | 46 | void precompute() {} 47 | 48 | int bfs(vector> &grid, vector> &vis, int n, int m, int r, int c) 49 | { 50 | 51 | cout << endl; 52 | vis[r][c] = 1; 53 | queue, int>> q; 54 | 55 | q.push({{r, c}, 1}); 56 | int area = grid[r][c]; 57 | 58 | int dirx[] = {-1, 0, 1, 0}; 59 | int diry[] = {0, 1, 0, -1}; 60 | 61 | while (!q.empty()) 62 | { 63 | int r = q.front().first.first; 64 | int c = q.front().first.second; 65 | q.pop(); 66 | 67 | for (int i = 0; i < 4; i++) 68 | { 69 | int nr = r + dirx[i]; 70 | int nc = c + diry[i]; 71 | 72 | if (nr >= 0 && nr < n && nc >= 0 && nc < m && vis[nr][nc] == 0 && grid[nr][nc] != 0) 73 | { 74 | vis[nr][nc] = 1; 75 | area += grid[nr][nc]; 76 | 77 | q.push({{nr, nc}, area}); 78 | } 79 | } 80 | } 81 | 82 | return area; 83 | } 84 | 85 | int find(vector> &grid, int n, int m) 86 | { 87 | int ans = 0; 88 | vector> vis(n, vector(m, 0)); 89 | 90 | rep(i, 0, n) 91 | { 92 | rep(j, 0, m) 93 | { 94 | if (grid[i][j] != 0) 95 | { 96 | int temp = bfs(grid, vis, n, m, i, j); 97 | 98 | ans = max(ans, temp); 99 | } 100 | } 101 | } 102 | 103 | return ans; 104 | } 105 | 106 | void solve() 107 | { 108 | int cnt = 0; 109 | int flag = 0; 110 | int n; 111 | cin >> n; 112 | int m; 113 | cin >> m; 114 | 115 | vector> grid; 116 | rep(i, 0, n) 117 | { 118 | vector v; 119 | rep(i, 0, m) 120 | { 121 | int x; 122 | cin >> x; 123 | v.push_back(x); 124 | } 125 | grid.push_back(v); 126 | } 127 | 128 | cnt = find(grid, n, m); 129 | cout << cnt << endl; 130 | } 131 | 132 | int32_t main() 133 | { 134 | ios_base::sync_with_stdio(false); 135 | cin.tie(NULL); 136 | precompute(); 137 | int T = 1; 138 | 139 | for (int i = 1; i <= T; i++) 140 | { 141 | 142 | solve(); 143 | } 144 | return 0; 145 | } -------------------------------------------------------------------------------- /w4/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w4/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w4/unoin_find.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | vector parent; 57 | vector size; 58 | vector ranker; 59 | 60 | void maker(ll a) 61 | { 62 | parent[a] = a; 63 | // size[a] = 1; 64 | ranker[a] =0; 65 | } 66 | 67 | ll find_parent(ll a) 68 | { 69 | if (parent[a] == a) 70 | return a; 71 | return parent[a] = find_parent(parent[a]); 72 | } 73 | 74 | 75 | void unionbyrank(int a, int b) { 76 | a = find_parent(a); 77 | b = find_parent(b); 78 | if (a != b) { 79 | if (ranker[a] < ranker[b]) 80 | swap(a, b); 81 | parent[b] = a; 82 | if (ranker[a] == ranker[b]) 83 | ranker[a]++; 84 | } 85 | } 86 | 87 | // void unionbysize(ll a, ll b) 88 | // { 89 | // a = find_parent(a); 90 | // b = find_parent(b); 91 | // if (a != b) 92 | // { 93 | // if (a < b) 94 | // swap(a, b); 95 | // parent[b] = a; 96 | // size[a] += size[b]; 97 | // } 98 | // } 99 | 100 | void solve() 101 | { 102 | int cnt = 0; 103 | int flag = 0; 104 | int n; 105 | cin >> n; 106 | int m; 107 | cin >> m; 108 | 109 | vector> v; 110 | 111 | parent.resize(n); 112 | size.resize(n); 113 | ranker.resize(n); 114 | 115 | rep(i,0,n){ 116 | maker(i);} 117 | 118 | // rep(i,0,n){ // already given parent array question 119 | // int a ; 120 | // cin >> a; 121 | // parent[i] = a ; 122 | // } 123 | 124 | 125 | rep(i, 0, m) 126 | { 127 | int a, b; 128 | cin >> a >> b; 129 | // unionbysize(a,b); 130 | unionbyrank(a,b); 131 | } 132 | 133 | 134 | // rep(i,0,n){ // disjoint set counter 135 | // if(i = find_parent(i)) cnt++; 136 | // } 137 | 138 | 139 | cout<< "parent of 3 " << find_parent(3) << endl; 140 | rep(i,0,n){ 141 | cout << parent[i] << " "; 142 | }cout <> T; 163 | 164 | for (int i = 1; i <= T; i++) 165 | { 166 | // cout << "Case #" << i << ": "; 167 | solve(); 168 | } 169 | return 0; 170 | } -------------------------------------------------------------------------------- /w5/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | // vector parent; 57 | // vector size; 58 | 59 | // int findp(int a) 60 | // { 61 | // if (a == parent[a]) 62 | // return a; 63 | // return parent[a] = findp(parent[a]); 64 | // } 65 | 66 | // void unionbysize(int a, int b) 67 | // { 68 | // a = findp(a); 69 | // b = findp(b); 70 | // if (a != b) 71 | // { 72 | // if (a > b) 73 | // swap(a, b); 74 | // parent[b] = a; 75 | // size[a] += size[b]; 76 | // } 77 | // } 78 | 79 | void dfs(vector> adj, vector &vis, int node){ 80 | vis[node] = 1; 81 | rep(i,0,adj[node].size()){ 82 | if(vis[adj[node][i]] == 0) dfs(adj,vis,adj[node][i]); 83 | } 84 | } 85 | 86 | void solve() 87 | { 88 | int flag = 0; 89 | int n; 90 | cin >> n; 91 | int m; 92 | cin >> m; 93 | 94 | // cout << n << " "<< m <> adj(n); 97 | rep(i, 0, m) 98 | { 99 | int x, y; 100 | cin >> x >> y; 101 | x--; 102 | y--; 103 | // cout << x << " " << y << endl; 104 | adj[x].push_back(y); 105 | adj[y].push_back(x); 106 | } 107 | 108 | // for(auto it : adj){ 109 | // for(auto itt : it){ 110 | // cout << itt << " " ; 111 | // }cout < vis(n, 0); 122 | 123 | int cnt = 0; 124 | 125 | rep(i, 0, n) 126 | { 127 | if (vis[i] == 0) 128 | { 129 | dfs(adj, vis, i); 130 | cnt++; 131 | } 132 | } 133 | 134 | cout << cnt; 135 | } 136 | 137 | int32_t main() 138 | { 139 | ios_base::sync_with_stdio(false); 140 | cin.tie(NULL); 141 | precompute(); 142 | int T = 1; 143 | 144 | // cin >> T; 145 | 146 | for (int i = 1; i <= T; i++) 147 | { 148 | // cout << "Case #" << i << ": "; 149 | solve(); 150 | } 151 | return 0; 152 | } -------------------------------------------------------------------------------- /w5/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int unsigned long long 15 | #define ll unsigned long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | void precompute() {} 54 | 55 | vector ans; 56 | 57 | void dfs(vector> edge, vector v, int n, int root, int crt) 58 | { 59 | 60 | if (edge[root][0] == -1 && edge[root][1] == -1) 61 | { 62 | ans.push_back(crt); 63 | return; 64 | } 65 | if (edge[root][0] != -1) 66 | { 67 | dfs(edge, v, n, edge[root][0], crt*10 + v[edge[root][0]]); 68 | } 69 | if (edge[root][1] != -1) 70 | { 71 | dfs(edge, v, n, edge[root][1], crt*10 + v[edge[root][1]]); 72 | } 73 | } 74 | 75 | void solve() 76 | { 77 | int cnt = 0; 78 | int flag = 0; 79 | int n; 80 | cin >> n; 81 | vi v(n); 82 | cin >> v; 83 | // cout << v << endl; 84 | 85 | vector> edge; 86 | rep(i, 0, n) 87 | { 88 | int x, y; 89 | cin >> x >> y; 90 | edge.push_back({x, y}); 91 | } 92 | 93 | // for(auto it : edge){ 94 | // cout << it[0]<< " " << it[1] <> T; 120 | 121 | for (int i = 1; i <= T; i++) 122 | { 123 | // cout << "Case #" << i << ": "; 124 | solve(); 125 | } 126 | return 0; 127 | } -------------------------------------------------------------------------------- /w5/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w5/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w6/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | #include 12 | using namespace std; 13 | 14 | #define int long long 15 | #define ll long long 16 | #define endl "\n" 17 | #define st string 18 | #define ld long double 19 | #define pb push_back 20 | #define vi vector 21 | #define all(x) x.begin(), x.end() 22 | #define rep(i, a, n) for (int i = a; i < n; ++i) 23 | #define drep(i, a, n) for (int i = n; i > a; --i) 24 | #define deb(x) cout << #x << x << endl; 25 | 26 | #define PI 3.14159265359 27 | #define inf 9e18 28 | 29 | template 30 | ostream &operator<<(ostream &output, const vector &data) 31 | { 32 | for (const T &x : data) 33 | { 34 | output << x << " "; 35 | } 36 | return output; 37 | } 38 | template 39 | istream &operator>>(istream &input, vector &data) 40 | { 41 | for (auto &item : data) 42 | { 43 | input >> item; 44 | } 45 | return input; 46 | } 47 | int setBits(int n) { return (__builtin_popcountll(n)); } 48 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 49 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 50 | constexpr int MOD = 1e9 + 7, mod = 998244353; 51 | 52 | const int N = 1e6 + 1; 53 | 54 | void precompute() {} 55 | 56 | void solve() 57 | { 58 | 59 | int n; 60 | cin >> n; 61 | int m; 62 | cin >> m; 63 | 64 | vector> edges(n); 65 | // cout << n << " " << m <> x >> y; 71 | if (x == y) 72 | continue; 73 | edges[x - 1].push_back(y - 1); 74 | edges[y - 1].push_back(x - 1); 75 | } 76 | 77 | int i = 0; 78 | 79 | // for(auto it : edges){ 80 | // cout << i+1 << " -- " ; 81 | // for(auto itt : it) cout << itt+1 << " "; 82 | // cout < vis(n, 0); 88 | priority_queue, greater> q; 89 | q.push(0); 90 | vis[0] = 1 ; 91 | 92 | vector ans; 93 | while (!q.empty()) 94 | { 95 | int node = q.top(); 96 | q.pop(); 97 | 98 | ans.push_back(node); 99 | for (auto it : edges[node]) 100 | { 101 | if (vis[it] == 0) 102 | { 103 | q.push(it); 104 | vis[it] = 1; 105 | } 106 | } 107 | } 108 | 109 | rep(i, 0, ans.size()) ans[i]++; 110 | // ans.resize(distance(ans.begin(), unique(ans.begin(), ans.end()))); 111 | cout << ans; 112 | } 113 | 114 | int32_t main() 115 | { 116 | ios_base::sync_with_stdio(false); 117 | cin.tie(NULL); 118 | precompute(); 119 | int T = 1; 120 | 121 | // cin >> T; 122 | 123 | for (int i = 1; i <= T; i++) 124 | { 125 | // cout << "Case #" << i << ": "; 126 | solve(); 127 | } 128 | return 0; 129 | } -------------------------------------------------------------------------------- /w6/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | using namespace std; 5 | 6 | #define int long long 7 | #define ll long long 8 | #define endl "\n" 9 | #define st string 10 | #define ld long double 11 | #define pb push_back 12 | #define vi vector 13 | #define all(x) x.begin(), x.end() 14 | #define rep(i, a, n) for (int i = a; i < n; ++i) 15 | #define drep(i, a, n) for (int i = n; i > a; --i) 16 | #define deb(x) cout << #x << x << endl; 17 | 18 | #define PI 3.14159265359 19 | #define inf 9e18 20 | 21 | typedef pair Pair; 22 | 23 | template 24 | ostream &operator<<(ostream &output, const vector &data) 25 | { 26 | for (const T &x : data) 27 | { 28 | output << x << " "; 29 | } 30 | return output; 31 | } 32 | template 33 | istream &operator>>(istream &input, vector &data) 34 | { 35 | for (auto &item : data) 36 | { 37 | input >> item; 38 | } 39 | return input; 40 | } 41 | int setBits(int n) { return (__builtin_popcountll(n)); } 42 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 43 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 44 | constexpr int MOD = 1e9 + 7, mod = 998244353; 45 | 46 | const int N = 1e6 + 1; 47 | 48 | void precompute() {} 49 | 50 | void solve() 51 | { 52 | int n; 53 | cin >> n; 54 | int src; 55 | cin >> src; 56 | 57 | vector>> v(n); 58 | vector vis(n, 0); 59 | rep(i, 0, n) 60 | { 61 | int edgecnt; 62 | cin >> edgecnt; 63 | rep(j, 0, edgecnt) 64 | { 65 | int x, w; 66 | cin >> x >> w; 67 | v[i].push_back({w, x}); 68 | } 69 | } 70 | 71 | vector dis(n, inf); 72 | dis[src] = 0; 73 | 74 | priority_queue, greater> pq; 75 | 76 | pq.push({0, src}); 77 | 78 | while (!pq.empty()) 79 | { 80 | int node = pq.top().second; 81 | int wgt = pq.top().first; 82 | pq.pop(); 83 | 84 | vis[node] = true; 85 | 86 | for (auto it : v[node]) 87 | if ((wgt + (it.first)) < dis[it.second]) 88 | { 89 | dis[it.second] = wgt + (it.first); 90 | pq.push({dis[it.second], it.second}); 91 | } 92 | } 93 | 94 | int ans = *max_element(all(dis)); 95 | if (ans == inf) 96 | ans = -1; 97 | cout << ans; 98 | } 99 | 100 | int32_t main() 101 | { 102 | ios_base::sync_with_stdio(false); 103 | cin.tie(NULL); 104 | precompute(); 105 | int T = 1; 106 | for (int i = 1; i <= T; i++) 107 | { 108 | solve(); 109 | } 110 | return 0; 111 | } -------------------------------------------------------------------------------- /w6/PPA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w6/PPA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w7/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w7/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w7/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w7/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w8/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w8/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w8/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w8/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w9/PA_Q1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w9/PA_Q2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w9/PPA_1.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } -------------------------------------------------------------------------------- /w9/PPA_2.cpp: -------------------------------------------------------------------------------- 1 | 2 | // Author : Kumar Akashdeep 3 | // Github : https://github.com/kadeep47 4 | 5 | // Problem : 6 | // Objective : 7 | 8 | // Time Complexity : 9 | // space Complexity : 10 | 11 | 12 | #include 13 | using namespace std; 14 | 15 | #define int long long 16 | #define ll long long 17 | #define endl "\n" 18 | #define st string 19 | #define ld long double 20 | #define pb push_back 21 | #define vi vector 22 | #define all(x) x.begin(), x.end() 23 | #define rep(i, a, n) for (int i = a; i < n; ++i) 24 | #define drep(i, a, n) for (int i = n; i > a; --i) 25 | #define deb(x) cout<<#x< 31 | ostream &operator<<(ostream &output, const vector &data) 32 | { 33 | for (const T &x : data) 34 | { 35 | output << x << " "; 36 | } 37 | return output; 38 | } 39 | template 40 | istream &operator>>(istream &input, vector &data) 41 | { 42 | for (auto &item : data) 43 | { 44 | input >> item; 45 | } 46 | return input; 47 | } 48 | int setBits(int n) { return (__builtin_popcountll(n)); } 49 | void print(bool x) { cout << (x ? "YES" : "NO") << '\n'; } 50 | void print(int x) { cout << (x == -1 ? "NO" : "YES") << "\n"; } 51 | constexpr int MOD = 1e9 + 7, mod = 998244353; 52 | 53 | const int N = 1e6 + 1; 54 | 55 | void precompute() {} 56 | 57 | void solve() 58 | { 59 | int cnt = 0; 60 | int flag = 0; 61 | int n; cin >> n; 62 | vi v(n); cin >> v; 63 | cout << cnt << endl; 64 | } 65 | 66 | int32_t main() 67 | { 68 | ios_base::sync_with_stdio(false); 69 | cin.tie(NULL); 70 | precompute(); 71 | int T = 1; 72 | 73 | // cin >> T; 74 | 75 | for (int i = 1; i <= T; i++) 76 | { 77 | // cout << "Case #" << i << ": "; 78 | solve(); 79 | } 80 | return 0; 81 | } --------------------------------------------------------------------------------