commit 8b321a709f927b016bc3e4557ced41a0ee9b981a parent e403ee5e221be27a14411d0b92529053c5ac7a8d Author: superpozycja <anna@superpozycja.net> Date: Tue, 29 Oct 2024 11:09:06 +0100 solve playlist Diffstat:
A | sorting_and_searching/playlist.cpp | | | 49 | +++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 49 insertions(+), 0 deletions(-)
diff --git a/sorting_and_searching/playlist.cpp b/sorting_and_searching/playlist.cpp @@ -0,0 +1,49 @@ +#include <bits/stdc++.h> + +using namespace std; + +using ui = unsigned int; +using l = long; +using ul = unsigned long; +using ll = long long; +using ull = unsigned long long; + +using vi = vector<int>; +using vui = vector<ui>; +using vl = vector<l>; +using vul = vector<ul>; +using vll = vector<ll>; +using vull = vector<ull>; + +void solve() +{ + int n; + cin >> n; + int k[n]; + for (int i = 0; i < n; i++) { + cin >> k[i]; + } + + int l = 0, r = 0; + int res = 0; + multiset<int> u; + + while (r < n) { + u.insert(k[r]); + while (u.count(k[r]) > 1) { + u.erase(u.find(k[l])); + l++; + } + res = max(res, r - l + 1); + r++; + } + + cout << res << "\n"; +} + +int main() +{ + ios::sync_with_stdio(0); + cin.tie(0); + solve(); +}