int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d", &n); ll sum = 0; for(int i = 0; i < n; ++i) { int a, b; scanf("%d %d", &a, &b); sum += a; s.pb(mp(a, -1)); s.pb(mp(b, 1)); } sort(s.begin(), s.end()); ll qtd = 0; ll maxi = sum; ll p = 0; for(int i = 0; i < s.size(); ++i) { if(s[i].S == -1) { qtd -= s[i].S; sum -= s[i].F; } ll foo = qtd * (ll)s[i].F + sum; if(foo > maxi) { maxi = foo; p = s[i].F; } if(s[i].S == 1) qtd -= s[i].S; } printf("%lld %lld\n", p, maxi); return 0; }
int main() { int n,x,c; scanf("%d", &n); for(int i=0; i<n; i++){ scanf("%d %d", &x, &c); m.pb(ii(x,c)); } sort(m.begin(), m.end()); memset(dp, -1, sizeof dp); printf("%d\n", m[0].second+recur(1,0)); return 0; }
int main(){ //maketestcase(); //freopen("input.txt", "r", stdin); int n; while(scanf("%d", &n) != EOF){ v.clear(); for(int i = 0; i < n; i++){ al[i].clear(); visited[i] = false; } for(int i = 0; i < n; i++){ int x, y; scanf("%d %d", &x, &y); v.pb(mkp(x,y)); } map<ii, vi> m; for(int i = 0; i < n; i++){ int x = v[i].first; int y = v[i].second; m[mkp(x/5, y/5)].pb(i); } int ix[5] = {0, 1, 1, 1, 0}; int iy[5] = {1, 1, 0, -1, -1}; repSTL(m, iter){ generateGraph(iter->second,iter->second); ii p = iter->first; for(int i = 0; i < 5; i++){ int x = p.first + ix[i]; int y = p.second + iy[i]; typeof(m.begin()) iter2 = m.find(mkp(x,y)); if(iter2 != m.end()){ generateGraph(iter->second, iter2->second); } } } m.clear(); int minS = 0; for(int i = 0; i < n; i++){ if(!visited[i]){ ii p = bipartite(i); minS += min(p.first, p.second); } } printf("%d\n", minS); }
int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); scanf("%d %d", &k, &n); for(int i = 0; i < n; ++i) { scanf("%d", c + i); foo.pb(mp(c[i], i)); } sort(foo.begin(), foo.end()); for(int i = 0; i < n; ++i) { int id = foo[i].S, x = foo[i].F; int mini = min(x, k); k -= mini; sol[id] = mini; } for(int i = 0 ; i < n; ++i) { if(i) printf(" "); printf("%d", sol[i]); } printf("\n"); return 0; }