Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <algorithm>
- #include <iostream>
- #include <map>
- #include <set>
- #include <string>
- #include <tuple>
- #include <unordered_map>
- #include <unordered_set>
- #include <vector>
- typedef long long ll;
- using namespace std;
- // 1 4 5 7 8
- // 2 3 4 5 6 8 9 10 12 140
- // 4 5 8
- vector<int> Intersection(vector<int>& a, vector<int>& b) {
- vector<int> result;
- int i = 0, j = 0;
- while (i < a.size() && j < b.size()) {
- if (a[i] < b[j]) ++i;
- else if (a[i] > b[j]) ++j;
- else {
- result.push_back(a[i]);
- ++i; ++j;
- }
- }
- return result;
- }
- int main1() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) cin >> a[i];
- int m = 0;
- cin >> m;
- vector<int> b(m);
- for (int i = 0; i < m; ++i) cin >> b[i];
- vector<int> result = Intersection(a, b);
- for (int x : result) cout << x << " ";
- return 0;
- }
- // 2 4 6 7 7 7 7 9 10 22 34
- int main2() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> n;
- int* b = new int[n];
- vector<int> a(n);
- for (int i = 0; i < n; ++i) { int v = 0; cin >> v; a[i] = v; b[i] = v; }
- int x = 0;
- cin >> x;
- auto position = lower_bound(a.begin(), a.end(), x, std::less<>());
- if (position != a.end() && *position == x) cout << "YES" << endl;
- else cout << "NO" << endl;
- auto position2 = lower_bound(b, b + n, x);
- if (position2 != b + n && *position2 == x) cout << "YES" << endl;
- else cout << "NO" << endl;
- delete[] b;
- return 0;
- }
- int main3() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) cin >> a[i];
- // 2 4 3 2 1
- int l = 1, r = n;
- while (l < r) {
- int mid = (r + l) / 2;
- if (a[mid] > a[mid - 1]) l = mid + 1;
- else r = mid;
- }
- cout << l - 1;
- return 0;
- }
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(nullptr);
- int n = 0;
- cin >> n;
- vector<int> a(n);
- for (int i = 0; i < n; ++i) cin >> a[i];
- int m = 0;
- cin >> m;
- // 2 4 3 2 1
- int l = 0, r = m;
- ll sum = 0;
- for (int i = l; i < r; ++i) sum += a[i];
- ll max_sum = sum;
- for (; r < n; ++l, ++r) {
- sum += a[r];
- sum -= a[l];
- max_sum = max(sum, max_sum);
- }
- cout << max_sum;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement