Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- int n;
- cin >> n;
- vector<ll>v(n);
- set<ll>dn;
- vector<pair<int,int>>pr;
- for (int i=0; i<n; i++) {
- cin >> v[i];
- if (!i) pr.insert(pr.end(), {v[i],1});
- else if (i&&v[i]>=v[i-1]) {
- if (v[i]!=v[i-1]) pr.insert(pr.end(), {v[i],0});
- for (auto &j:pr) {
- j.second++;
- }
- }
- else {
- int f=0;
- for (auto x:pr) {
- if (x.first == v[i]) f=1;
- }
- set<int>s;
- for (auto x:pr) {
- if (x.first > v[i]) s.insert(x.second);
- }
- if (!f) pr.insert(pr.end(), {v[i],*s.rbegin()});//
- for (int j=0; j<pr.size(); j++) {
- if (pr[j].first >v[i]) {
- dn.insert(pr[j].first*pr[j].second);
- pr.erase(pr.begin()+j);
- j--;
- }
- else pr[j].second++;
- }
- }
- }
- for (int j=0; j<pr.size(); j++) {
- dn.insert(pr[j].first * pr[j].second);
- }
- cout << *dn.rbegin() << endl;
- //4 3 4 2 6
- //
- //2 1 4 5 1 3 3
- //21 12 41,13 51,42,14 15 16,31 17,32-
- // 2 2,5 2,5,8 2,5,8,6,7
- // 1 2 1 2 2
- // 1 2 2
- // 1 2 3 4 3 4 4
- // 1 2 3 4 5 4 8 5 8
- // 1 5 8 8
- // 1 2 3 6 3 8
- // 1 2 3 7 3 8
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment