Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define rep(i,a,b) for (i=a;i<b;i++)
- #define rep2(i,a,b) for (i=a;i>=b;i--)
- #define mod 1000000007
- //#include<boost/multiprecision/cpp_int.hpp>
- //using namespace boost::multiprecision;
- #define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
- #define INF 1e9+5
- #define f first
- #define s second
- #define endl '\n'
- #define ll long long
- #define ii pair <int,int>
- #define pll pair <ll,ll>
- #define vi vector <int>
- #define vl vector <ll>
- #define vvi vector < vi >
- #define vii vector < ii >
- #define vvii vector < vii >
- #define vll vector < ll >
- #define vb vector <bool>
- #define pb push_back
- #define mk make_pair
- #define sz(a) a.size()
- #define all(a) a.begin(),a.end()
- #define rall(a) a.rbegin(),a.rend()
- #define cset(a) __builtin_popcountll(a)
- #include<string>
- #include<sstream>
- using namespace std;
- int a[1000001];
- int main()
- {
- FIO;
- int t, n, m, i, top_i, x;
- ll maxx, cur_maxx;
- cin>>t;
- while(t--)
- {
- cin>>n>>m;
- memset(a,0,sizeof(a));
- rep(i,0,m)
- {
- cin>>x;
- a[x]++;
- }
- stack<int>ss;
- i = 0;
- maxx = 0;
- while(i <= n)
- {
- if( ss.empty() || a[ss.top()] <= a[i])
- { ss.push(i);
- i++;
- }
- else
- {
- top_i = ss.top();
- ss.pop();
- if( ss.empty())
- cur_maxx = a[top_i]*i;
- else
- cur_maxx = a[top_i]*(i - ss.top() - 1);
- if( cur_maxx > maxx)
- maxx = cur_maxx;
- }
- }
- while( !ss.empty())
- {
- top_i = ss.top();
- ss.pop();
- if( ss.empty())
- cur_maxx = a[top_i]*i;
- else
- cur_maxx = a[top_i]*(i - ss.top() - 1);
- if( cur_maxx > maxx)
- maxx = cur_maxx;
- }
- cout<<maxx<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment