P2672 salesman
answer
Shocked exclamation exclamation exclamation mark
Greedy bold guess even lead to AC! ! !
Not the skin began to talk about the mentality of this question here thanks SY & LZ, online mod
First we consider when X = 1, then the ans is max Si * 2 + ai (1 <= i <= n)
Then how to do it
---- ---- To be continued
Code
#include<bits/stdc++.h> using namespace std; const int maxn=1e5+10; int n,k,rode; long long ans=0; struct node { int s,a,dt; }peo[maxn]; bool cmp(node x,node y) { return x.a >y.a ; } int main() { scanf("%d\n",&n); if(n==1) { int x,y; scanf("%d\n",x*2+y); return 0; } for(int i=1;i<=n;i++) scanf("%d",&peo[i].s ); for(int i=1;i<=n;i++) { scanf("%d",&peo[i].a ); peo[i].dt =peo[i].s *2+peo[i].a ; if(peo[i].dt>ans) { ans=peo[i].dt ; k=i; } } printf("%ld\n",ans); rode=peo[k].s; peo[k].a =-1; sort(peo+1,peo+n+1,cmp); for(int i=1;i<n;i++) { if(peo[i].s <=rode ) { ans+=peo[i].a ; printf("%ld\n",ans); } Else { Years + = peo [i] .a; years - rode = * 2 ; years + = peo [i] .s * 2 ; rode = peo [i] .s; printf ( " % ld \ n " , year); } } Return 0 ; }