vector <int> reconstruct(string signature) { cout << signature << endl; VI ret; for(int i=0;i<size(signature);i++) { if(signature[i] == 'I') { for(int j=0;j<=i;j++) { ret.pb(i+1-j); } VI tmp = reconstruct(signature.substr(i+1)); for(int j=0;j<size(tmp);j++) ret.pb(tmp[j] + i + 1); return ret; } } ret.pb(size(signature)+1); for(int i=0;i<size(signature);i++) { ret.pb(size(signature)-i); } return ret; }
void period(const VI& v, int A, int L, int n, LL& count) { if (v.size() == n) { count++; return; } VI t = v; t.pb(0); int At = 0; int Lt = L; period(t, At, Lt, n, count); if (A != 2) { t = v; t.pb(1); At = A+1; Lt = L; period(t, At, Lt, n, count); } if (L == 0) { t = v; t.pb(2); At = 0; Lt = 1; period(t, At, Lt, n, count); } }
II euler_check(const VVI& g) { VI v; int odd = 0; RSZ(i, g) if (SZ(g[i])%2 == 1) { odd++; v.pb(i); } if (!odd) v.pb(0); v.pb(-1); if ((odd == 0 || odd == 2) && connect(g, v[0])) return MP(v[0], v[1]); else return MP(-1, -1); }
vector <int> OnTheFarmDivTwo::animals(int heads, int legs) { VI res; for(int i=0; i<=heads; i++) { if((i*2)+(heads-i)*4==legs) { res.pb(i); res.pb(heads-i); return res; } } return res; }
int getMinimum(vector <int> lines) { target = lines; memset(memo, -1, sizeof(memo)); for(int i=0;i<size(lines);i++) ls.pb(lines[i]); ls.pb(0); sort(ls.begin(),ls.end()); ls.erase(unique(ls.begin(), ls.end()), ls.end()); return go(0,0) - 1; }
int ObjectPacking::smallBox(int objWidth, int objLength, vector <int> boxWidth, vector <int> boxLength) { VI res; rep(i,sz(boxWidth)){ if(boxWidth[i]>=objWidth && boxLength[i]>=objLength) res.pb(boxWidth[i]*boxLength[i]); if(boxWidth[i]>=objLength && boxLength[i]>=objWidth) res.pb(boxWidth[i]*boxLength[i]); } if(sz(res)<1) return -1; sort(full(res)); return res[0]; }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n; s(n); rep(i,n) { int a; s(a); v1.pb(a); v2.pb(a); }
int removeThem(vector<int> a, int K) { k=K; n=a.size(); a0.clear(); a1.clear(); a2.clear(); a3.clear(); for(int i=0;i<a.size();++i) { if(a[i]%4==0)a0.pb(a[i]); if(a[i]%4==1)a1.pb(a[i]); if(a[i]%4==2)a2.pb(a[i]); if(a[i]%4==3)a3.pb(a[i]); } sort(a0.rbegin(),a0.rend()); sort(a1.rbegin(),a1.rend()); sort(a2.rbegin(),a2.rend()); sort(a3.rbegin(),a3.rend()); B[0][0]=a0[0]; for(int i=1;i<a0.size();++i) { B[0][i]=B[0][i-1]+a0[i]; } B[1][0]=a1[0]; for(int i=1;i<a1.size();++i) { B[1][i]=B[1][i-1]+a1[i]; } B[2][0]=a2[0]; for(int i=1;i<a2.size();++i) { B[2][i]=B[2][i-1]+a2[i]; } B[3][0]=a3[0]; for(int i=1;i<a3.size();++i) { B[3][i]=B[3][i-1]+a3[i]; } fill(dp,-1); return f(0,0,0,0); }
int main(){ #ifdef LOCAL freopen("/Users/apple/input.txt", "r", stdin); // freopen("/Users/apple/out.txt", "w", stdout); #endif while(si(n) != EOF) { rep(i, n) si(a[i]); minST.build(a, n, MIN); gcdST.build(a, n, GCD); int l = 1, r = n + 1, mid; while(l < r) { mid = (l + r) >> 1; if(check(mid)) l = mid + 1; else r = mid; } int len = l - 1; VI tmp; for(int i = 0; i + len <= n; i ++) { int j = i + len - 1; if(minST.query(i, j) == gcdST.query(i, j)) tmp.pb(i); } int sz = tmp.size(); printf("%d %d\n",sz, len - 1); rep(i, sz - 1) printf("%d ", tmp[i] + 1); put(tmp[sz-1] + 1); } return 0; }
int main(){ //std::ios_base::sync_with_stdio(0); //FI; VI num; int l, i, n; while(si(n) != EOF){ num.pb(n); sort(num.begin(), num.end()); if(num.size() % 2 == 0){ pi((num[num.size() / 2] + num[num.size() / 2 - 1]) / 2); NL; } else{ pi(num[num.size() / 2]); NL; } } return 0; }
int main() { //freopen("in", "r", stdin); int n, m; while(cin >> n >> m) { VI vec; REP(i, n) { int x; scanf("%d", &x); vec.pb(x); } int l = vec.back(), r = 2e6 + 10; int ret = -1; while(l <= r) { int mid = (l + r) / 2; int ll = 0, rr = n-1; int num = 0; while(ll <= rr) { if(vec[ll] + vec[rr] > mid) --rr; else ++ll, --rr; ++num; } if(num <= m) ret=mid, r = mid - 1; else l = mid + 1; } cout << ret << endl; }
rep(k,n) { ll c=v[k]; ll a=v[i]; ll b=v[j]; v1.pb(a*b+c); }
int main() { #ifdef MANGOGAO freopen("data.in", "r", stdin); #endif int n, m, x; scanf("%d%d", &n, &m); int now, pre; dp[0][0][0] = 1; for (int i = 1; i <= n; i++) { scanf("%d", &x); now = i & 1; pre = 1 - now; for (int j = 0; j <= m; j++) for (int k = 0; k <= m; k++) { dp[now][j][k] |= dp[pre][j][k]; if (j >= x) { dp[now][j][k] |= dp[pre][j - x][k]; if (k >= x) dp[now][j][k] |= dp[pre][j - x][k - x]; } } } VI ans; for (int i = 0; i <= m; i++) if (dp[now][m][i]) ans.pb(i); printf("%d\n", ans.size()); for (int i = 0; i < (int)ans.size(); i++) printf("%d%c", ans[i], i == (int)ans.size() - 1 ? '\n' : ' '); return 0; }
unsigned ll MaxArea() { if(!A.sz) return 0; A.pb(0); int i=0; unsigned ll mxArea=0; stack<unsigned ll> S; while(i<A.sz) { if(S.empty() || A[i]>=A[S.top()]) S.push(i++); else { int top=S.top(); S.pop(); mxArea=max(mxArea, A[top]*(S.empty()?i:i-S.top()-1)); } } return mxArea; }
int getNumber(vector<int> c, int X) { sort(all(c)); int ans=1e9; VI a; for(int i=0;i<c.size();++i) { a.pb(c[i]+X); a.pb(c[i]-X); } sort(all(a)); for(int i=0;i<a.size();++i) { for(int j=i;j<a.size();++j) { bool ok=true; for(int k=0;k<c.size();++k) { ok=ok&&(f(c[k]+X,a[i],a[j]) || f(c[k]-X,a[i],a[j])); } if(ok)ans=min(ans,a[j]-a[i]); } } return ans; }
void init_primes() { mem(vis, 0); int m = sqrt(N + 0.5); FOR(i, 2, m) if(!vis[i]) for(int j = i * i; j <= N; j += i) vis[j] = 1; FOR(i, 2, N) if(!vis[i]) primes.pb(i); }
vector <string> SequenceOfNumbers::rearrange(vector <string> sequence) { VI res; rep(i,sz(sequence)){ stringstream ss(sequence[i]); int x; ss>>x; res.pb(x); }
void primes(){ memset(p,1,sizeof(p)); for(int i=2;i<32005;i++) if(p[i]){ pr.pb(i); for(int j=i*i;j<32005;j+=i) p[j]=0; } }
void dfs1(int p) { visited[p]=1; rep(i,sz(v[p])) { if(!visited[v[p][i]]) dfs1(v[p][i]); } topo.pb(p); }
int getMin(string lamps) { s.clear(); for(int i=0;i<(int)lamps.length();++i)s.pb(lamps[i]=='Y'); fill(dp,-1); int ans=f(0,s[0],0,0); return ans; }
int main() { int n; s(n); VI v; rep(i,n) { ll a;sll(a); v.pb(a); }
int main(){ int n, s; cin >> n >> s; int sum = 0; VI v; REP(i,n){ int x; cin >> x; v.pb(x); }
VI getbit(int n) { int pos=0; clr(ans); while(n) { if(n&1) ans.pb(pos); n>>=1; pos++; } return ans; }
int main() { ios_base::sync_with_stdio(false);cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n; cin>>n; rep(i,n) { int a;cin>>a;v.pb(a); }
int main() { int n; cin>>n; memset(v,-1,sizeof v); for(int i=1;i<=n;i++){ cin>>a[i]; if(a[i]==i) { g.pb(i); bb[i]=1; } } int f=SZ(g); int cnt=0; for(int i=1;i<=n;i++){ if(v[i]==-1){ cnt++; int x=i,pre=0; while(v[x]==-1){ v[x]=cnt; pre=x; x=a[x]; } if(v[x]==cnt){ a[pre]=pre; //cout<<x<<endl; } } } for(int i=1;i<=n;i++){ if(a[i]==i&& !bb[i]) g.pb(i); } for(int i=1;i<SZ(g);i++) a[g[i]]=g[0]; if(f) cout<<SZ(g)-1<<endl; else cout<<SZ(g)<<endl; for(int i=1;i<=n;i++) cout<<a[i]<<" "; return 0; }
int main(void) { int N, x; while(sfi(N) && N) { rep(i, N) sfi(x), A.pb(x); printf("%llu\n",MaxArea()); A.clear(); } return (0); }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n,m,k; s(n);s(m);s(k); VI v; rep(i,n) { int a;s(a); v.pb(a); }
int main() { //freopen("in", "r", stdin); int n; while(cin >> n) { VI vec; REP(i, n) { int x; scanf("%d", &x); int id = lower_bound(vec.begin(), vec.end(), x) - vec.begin(); if(id == vec.size()) vec.pb(x); else { vec[id] = x; } } cout << n - vec.size() << endl; }
int main(){ //std::ios_base::sync_with_stdio(0); #ifdef CFw while(1){ #endif //FI;FO; int t, z = 0, l, i, n, len; v.clear(); M.clear(); si(t); rep(l,t){ si(n); if(!M[n]){ v.pb(n); M[n] = 1; } } si(n); while(n--){ si(t); z = bsl(t,v.size()); if(z == -1) ps("X"); else pi(v[z]); ps(" "); z = bsu(t,v.size()); if(z == -1) ps("X"); else pi(v[z]); NL; } #ifdef CFw NL; }
int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif int n; s(n);int maxv,minv; int maxp,minp; maxp=minp=0; maxv=-1;minv=99999; VI v; rep(i,n) { int a;s(a); v.pb(a); }