Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define ff first
- #define ss second
- #define pb push_back
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- _test
- {
- int n;
- cin>>n;
- int ans = 0, sum, mmax, f;
- set<int> st;
- vector<int> poss;
- vector<int> done(n*n+1);
- for(int i=1; i<=n; i++)
- {
- for(int j=1; j<=n; j++)
- {
- if(done[i*j]) continue;
- done[i* j] = 1;
- poss.pb(i*j);
- }
- }
- int i, avail, tmp;
- sort(poss.rbegin(), poss.rend());
- for(auto x: poss)
- {
- if(x*n < ans) break;
- sum = mmax = 0;
- f = 1;
- for(avail=1; avail<=n; avail++)
- st.insert(avail);
- for(i=n; i>=1; i--)
- {
- if(st.lower_bound((x/i)+1) == st.begin())
- {
- f = 0;
- break;
- }
- tmp = *(--st.lower_bound((x/i)+1));
- st.erase(tmp);
- mmax = max(mmax, tmp * i);
- sum += tmp * i;
- }
- if(!f) continue;
- ans = max(ans, sum-mmax);
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment