//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
#define ff first
#define s second
int n,m,a[MAX];
vector<pair<pii,pii > > v;
int cmp(pair<pii,pii > p,pair<pii,pii > q){
if(p.ff.ff!=q.ff.ff)
return p.ff.ff>q.ff.ff;
else if(p.ff.s!=q.ff.s)
return p.ff.s>q.ff.s;
else
return p.s.ff<q.s.ff;
}
int main(){
int st,ed,r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll sum=0;string p;
si(t);
f(j,1,t+1){
v.clear();
si(n);
f(i,1,n)
si(a[i]);
sum=0;
st=1;
f(i,1,n){
if(a[i]+sum>=0){
sum+=a[i];
ed=i+1;
if(sum>=0)
v.pb(mp(mp(sum,ed-st),mp(st,ed)));
}
else{
sum=0;
st=i+1;
}
}
sort(all(v),cmp);
if(v.size()==0)
cout<<"Route "<<j<<" has no nice parts";
else
cout<<"The nicest part of route "<<j<<" is between stops "<<v[0].s.ff<<" and "<<v[0].s.s;
nl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
#define ff first
#define s second
int n,m,a[MAX];
vector<pair<pii,pii > > v;
int cmp(pair<pii,pii > p,pair<pii,pii > q){
if(p.ff.ff!=q.ff.ff)
return p.ff.ff>q.ff.ff;
else if(p.ff.s!=q.ff.s)
return p.ff.s>q.ff.s;
else
return p.s.ff<q.s.ff;
}
int main(){
int st,ed,r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll sum=0;string p;
si(t);
f(j,1,t+1){
v.clear();
si(n);
f(i,1,n)
si(a[i]);
sum=0;
st=1;
f(i,1,n){
if(a[i]+sum>=0){
sum+=a[i];
ed=i+1;
if(sum>=0)
v.pb(mp(mp(sum,ed-st),mp(st,ed)));
}
else{
sum=0;
st=i+1;
}
}
sort(all(v),cmp);
if(v.size()==0)
cout<<"Route "<<j<<" has no nice parts";
else
cout<<"The nicest part of route "<<j<<" is between stops "<<v[0].s.ff<<" and "<<v[0].s.s;
nl;
}
return 0;
}
No comments:
Post a Comment