版本比较
反悔贪心
正文
增加 8 行删除 8 行
345 行未改动全部展开34634734834935035135235335466 行未改动4214224234244254264274284298 行未改动43843944044144244344444544690 行未改动537538539540541542543544545242 行未改动全部展开788789790791792793794795796139 行未改动全部展开93693793893994094194294394494594694794894995095195295389 行未改动345 行未改动全部展开cnt[p] --, cnt[q] += 2;q2.push((node){b[p] - a[p], p});q3.push((node){- a[p], p});q5.push((node){a[q] - b[q], q});}}printf("%lld\n", ans);for(int i = 1; i <= n; ++i) printf("%lld", cnt[i]);return 0;66 行未改动return f ? -s : s;}int main(){n = read(), P = read(), S = read();for(int i = 1; i <= n; ++i) a[i].val = read(), a[i].id = i;for(int i = 1; i <= n; ++i) b[i].val = read(), b[i].id = i;sort(a + 1, a + n + 1);8 行未改动int Max = 0, opt = 0, p, q;while(!q2.empty() && vis[q2.top().id] != 0) q2.pop();if(!q2.empty() && q2.top().val > Max) {Max = q2.top().val;opt = 1, p = q2.top().id;}while(!q1.empty() && vis[q1.top().id] != 0) q1.pop();while(!q3.empty() && vis[q3.top().id] != 1) q3.pop();if(!q1.empty() && !q3.empty() && q1.top().val + q3.top().val > Max) {90 行未改动}a[MAXN], b[MAXN], c[MAXN];int n, X, Y, Z, ans = 0;int vis[MAXN];priority_queue<node> q1, q2, q3;int read() {int s = 0, f = 0;char ch = getchar();242 行未改动全部展开for(int i = 1; i <= K; ++i) {ans += a[i].val + b[i].val;vis[a[i].id] ++, vis[b[i].id] += 2;}for(int i = 1; i <= n; ++i) L -= (vis[i] == 3);sort(a + 1, a + n + 1, cmp2), sort(b + 1, b + n + 1, cmp2);for(int i = 1; i <= n; ++i) {q1.push((node){a[i].val, i});q2.push((node){-a[i].val, i});139 行未改动全部展开if(this->lmax > this->sum + b.lmax) res.lmax = this->lmax, res.lmaxid = this->lmaxid;else res.lmax = this->sum + b.lmax, res.lmaxid = b.lmaxid;if(this->lmin < this->sum + b.lmin) res.lmin = this->lmin, res.lminid = this->lminid;else res.lmin = this->sum + b.lmin, res.lminid = b.lminid;if(this->rmax + b.sum < b.rmax) res.rmax = b.rmax, res.rmaxid = b.rmaxid;else res.rmax = this->rmax + b.sum, res.rmaxid = this->rmaxid;if(this->rmin + b.sum > b.rmin) res.rmin = b.rmin, res.rminid = b.rminid;else res.rmin = this->rmin + b.sum, res.rminid = this->rminid;res.maxv = this->rmax + b.lmax, res.maxl = this->rmaxid, res.maxr = b.lmaxid;if(res.maxv < this->maxv) res.maxv = this->maxv, res.maxl = this->maxl, res.maxr = this->maxr;if(res.maxv < b.maxv) res.maxv = b.maxv, res.maxl = b.maxl, res.maxr = b.maxr;res.minv = this->rmin + b.lmin, res.minl = this->rminid, res.minr = b.lminid;if(res.minv > this->minv) res.minv = this->minv, res.minl = this->minl, res.minr = this->minr;if(res.minv > b.minv) res.minv = b.minv, res.minl = b.minl, res.minr = b.minr;res.rev = false;89 行未改动345 行未改动全部展开34634734834935035135235335466 行未改动4214224234244254264274284298 行未改动43843944044144244344444544690 行未改动537538539540541542543544545242 行未改动全部展开788789790791792793794795796139 行未改动全部展开93693793893994094194294394494594694794894995095195295389 行未改动345 行未改动全部展开cnt[p] --, cnt[q] += 2;q2.push((node){b[p] - a[p], p});q3.push((node){- a[p], p});q5.push((node){a[q] - b[q], q});}}printf("%lld\n", ans);for(int i = 1; i <= n; ++i) printf("%lld", cnt[i]);return 0;66 行未改动return f ? -s : s;}int main(){n = read(), P = read(), S = read();for(int i = 1; i <= n; ++i) a[i].val = read(), a[i].id = i;for(int i = 1; i <= n; ++i) b[i].val = read(), b[i].id = i;sort(a + 1, a + n + 1);8 行未改动int Max = 0, opt = 0, p, q;while(!q2.empty() && vis[q2.top().id] != 0) q2.pop();if(!q2.empty() && q2.top().val > Max) {Max = q2.top().val;opt = 1, p = q2.top().id;}while(!q1.empty() && vis[q1.top().id] != 0) q1.pop();while(!q3.empty() && vis[q3.top().id] != 1) q3.pop();if(!q1.empty() && !q3.empty() && q1.top().val + q3.top().val > Max) {90 行未改动}a[MAXN], b[MAXN], c[MAXN];int n, X, Y, Z, ans = 0;int vis[MAXN];priority_queue<node> q1, q2, q3;int read() {int s = 0, f = 0;char ch = getchar();242 行未改动全部展开for(int i = 1; i <= K; ++i) {ans += a[i].val + b[i].val;vis[a[i].id] ++, vis[b[i].id] += 2;}for(int i = 1; i <= n; ++i) L -= (vis[i] == 3);sort(a + 1, a + n + 1, cmp2), sort(b + 1, b + n + 1, cmp2);for(int i = 1; i <= n; ++i) {q1.push((node){a[i].val, i});q2.push((node){-a[i].val, i});139 行未改动全部展开if(this->lmax > this->sum + b.lmax) res.lmax = this->lmax, res.lmaxid = this->lmaxid;else res.lmax = this->sum + b.lmax, res.lmaxid = b.lmaxid;if(this->lmin < this->sum + b.lmin) res.lmin = this->lmin, res.lminid = this->lminid;else res.lmin = this->sum + b.lmin, res.lminid = b.lminid;if(this->rmax + b.sum < b.rmax) res.rmax = b.rmax, res.rmaxid = b.rmaxid;else res.rmax = this->rmax + b.sum, res.rmaxid = this->rmaxid;if(this->rmin + b.sum > b.rmin) res.rmin = b.rmin, res.rminid = b.rminid;else res.rmin = this->rmin + b.sum, res.rminid = this->rminid;res.maxv = this->rmax + b.lmax, res.maxl = this->rmaxid, res.maxr = b.lmaxid;if(res.maxv < this->maxv) res.maxv = this->maxv, res.maxl = this->maxl, res.maxr = this->maxr;if(res.maxv < b.maxv) res.maxv = b.maxv, res.maxl = b.maxl, res.maxr = b.maxr;res.minv = this->rmin + b.lmin, res.minl = this->rminid, res.minr = b.lminid;if(res.minv > this->minv) res.minv = this->minv, res.minl = this->minl, res.minr = this->minr;if(res.minv > b.minv) res.minv = b.minv, res.minl = b.minl, res.minr = b.minr;res.rev = false;89 行未改动