제출 #713988

#제출 시각아이디문제언어결과실행 시간메모리
713988vqpahmad수열 (APIO14_sequence)C++14
0 / 100
2062 ms7824 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ll long long #define pii pair<int,int> #define F first #define S second #define endl '\n' #define pb push_back #define sz(a) (int)a.size() #define all(a) a.begin(),a.end() const int mod = 1e9 + 7; const int N = 1e6 + 15; const ll inf = 1e18; set<int> av; set<int> ct; const int off = (1<<20); int t[off*2]; int combine(int u,int v){ return u+v; } void update(int i,int u){ i+=off; t[i] = u; while (i/=2){ t[i] = combine(t[i*2],t[i*2+1]); } } int get(int l, int r, int idx=1, int lo=0, int hi=off){ if (lo>=r||hi<=l) return 0; if (lo>=l&&hi<=r) return t[idx]; int mi = (lo+hi)/2; return combine(get(l,r,idx*2,lo,mi),get(l,r,idx*2+1,mi,hi)); } int32_t main(){ ios_base::sync_with_stdio(0);cin.tie(0); int n,k; cin >> n >> k; ct.insert(0); ct.insert(n); vector<int> a(n); for (int i=0;i<n;i++){ cin >> a[i]; update(i,a[i]); } for (int i=1;i<=n-1;i++) av.insert(i); int ans = 0; for (int i=0;i<k;i++){ int best = 0; int pos = *av.begin(); for (auto it : av){ int lo = *--ct.upper_bound(it); int hi = *ct.upper_bound(it); int cur = get(lo,it)*get(it,hi); if (cur > best){ best = cur; pos = it; } } ct.insert(pos); av.erase(pos); ans += best; } cout << ans << '\n'; for (auto it : ct){ if (it==0||it==n) continue; cout << it << ' '; } cout << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...