-
Solution:-
#include <bits/stdc++.h> using namespace std; int maxChunksToSorted(vector<int> &arr) { int maxi = 0; int cnt = 0; for (int i = 0; i < arr.size(); i++) { maxi = max(maxi, arr[i]); if (maxi == i) { cnt++; } // cout << cnt << endl; // cout << maxi << " " << i << endl; } return cnt; } int main() { int n; cin >> n; vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; } cout << maxChunksToSorted(v) << endl; return 0; }
- N Cranes
Solution:-
#include <bits/stdc++.h> using namespace std; bool solution(vector<long long int> A, vector<long long int> P, long long int B, long long int E) { vector<pair<long long int, long long int>> v(A.size()); for (long long int i = 0; i < P.size(); i++) { v[i] = make_pair(P[i] - A[i] > 0 ? P[i] - A[i] : 0, P[i] + A[i]); cout << "Loop1" << endl; } // cout<<"Hello"<<endl; sort(v.begin(), v.end()); if (B > E) { for (long long int i = P.size() - 1; i >= 0; i--) { cout << "B:- " << B << endl; if (v[i].second >= B && v[i].first < B) { B = v[i].first > E ? v[i].first : E; } if (B == E) { cout << "B:- " << B << endl; return true; } } } else if (B < E) { for (long long int i = 0; i < P.size(); i++) { cout << "B:- " << B << endl; if (v[i].first <= B && v[i].second > B) { B = v[i].second < E ? v[i].second : E; } if (B == E) { cout << "B:- " << B << endl; return true; } } } return false; } int main() { long long int n, b, e; cin >> n; vector<long long int> A(n); vector<long long int> P(n); for (long long int i = 0; i < n; i++) { cin >> A[i]; } for (long long int i = 0; i < n; i++) { cin >> P[i]; } cin >> b >> e; if (solution(A, P, b, e)) { cout << "Works"; } else cout << "Doesn't work" << endl; return 0; }
- N Cranes
coding-discussions-ieeesbm-mrityunjay-shukla's Introduction
coding-discussions-ieeesbm-mrityunjay-shukla's People
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.