Download spoj_cpp_clean/ADAPLANT/ADAPLANT-20.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 2.45 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ADAPLANT/ADAPLANT-20.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/ADAPLANT/ADAPLANT-20.cpp
-
curl -L -o ADAPLANT-20.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ADAPLANT/ADAPLANT-20.cpp
2.45 kB
| /** | |
| * Author : Mr_Sohel | |
| * Task : | |
| * Algo : Multiset + Sliding Window | |
| **/ | |
| using namespace std; | |
| using ll = long long; | |
| using db = double; | |
| using ld = long double; | |
| using ull = unsigned long long; | |
| using pii = pair<int, int>; | |
| using pll = pair<ll, ll>; | |
| const ld PI = acos((ld) - 1); | |
| const int MOD = 1e9 + 7; | |
| const ll INF = 2e18 + 1; | |
| const ld EPS = 1e-9; | |
| const int MX = 1e5 + 2; | |
| template < typename Arg1 > | |
| void __f(const char* name, Arg1&& arg1) { | |
| cerr << name << " = " << arg1 << endl; | |
| } | |
| template < typename Arg1, typename... Args> | |
| void __f(const char* names, Arg1&& arg1, Args&&... args) { | |
| const char* comma = strchr(names + 1, ','); | |
| cerr.write(names, comma - names) << " = " << arg1 << " | "; | |
| __f(comma + 1, args...); | |
| } | |
| int a[MX]; | |
| int main() { | |
| clock_t tStart = clock(); | |
| freopen("in.txt", "r", stdin); | |
| freopen("out.txt", "w", stdout); | |
| unsyncIO; | |
| int t; cin >> t; | |
| while (t--) { | |
| int n, k; | |
| cin >> n >> k; | |
| for (int i = 0; i < n; i++) cin >> a[i]; | |
| int i = 0, j = k + 1, ans = 0; | |
| multiset<int> mp; // i wil try with multimap later | |
| for (i = 0; i <= j and i < n; i++) { | |
| mp.insert(a[i]); | |
| } | |
| i = 0; | |
| auto f = mp.begin(), l = --mp.end(); | |
| // l--; | |
| ans = max(ans, *l - *f); | |
| while (j < n) { | |
| f = mp.begin(), l = --mp.end(); | |
| ans = max(ans, (*l - *f)); | |
| /*for (auto in : mp) { | |
| cout << in << " "; | |
| } | |
| cout << "ans = " << ans << endl;*/ | |
| auto x = mp.find(a[i]); | |
| mp.erase(x); | |
| j++; | |
| i++; | |
| mp.insert(a[j]); | |
| } | |
| cout << ans << endl; | |
| } | |
| cerr << "\nRuntime: " << (ld) (clock() - tStart) / CLOCKS_PER_SEC << " Seconds" << endl; | |
| return 0; | |
| } |