-
Notifications
You must be signed in to change notification settings - Fork 0
/
F.cpp
92 lines (89 loc) · 2.27 KB
/
F.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0);cin.tie(0)
long long ara[200005],perm[200005],mark[200005],mp[200005];
int main()
{
fastio;
long long t,n,i,mx,cnt,cur;
cin>>t;
while(t--)
{
cin>>n;
for(i=0;i<n;i++)
{
mark[i]=0;
mp[i]=0;
cin>>ara[i];
}
for(i=0;i<n;i++)
cin>>perm[i];
vector<pair<long long,long long> > vect;
for(i=0;i<n;i++)
vect.push_back(make_pair(ara[i],i));
sort(vect.begin(),vect.end());
mx=vect[n-1].first;
cnt=1;
cur=n-1;
mp[vect[n-1].second]=1;
//cout<<mx<<endl;
for(i=0;i<n-1;i++)
{
mark[perm[i]-1]=1;
if(mp[perm[i]-1]==0)
{
cur--;
if(cur<0)
break;
while(mark[vect[cur].second]==1){
cur--;
if(cur<0)
break;
}
if(cur<0)
break;
mp[vect[cur].second]=1;
if(vect[cur].first*(i+2)>mx)
{
mx=vect[cur].first*(i+2);
cnt=i+2;
}
}
else
{
mp[perm[i]-1]=0;
cur--;
if(cur<0)
break;
while(mark[vect[cur].second]==1){
cur--;
if(cur<0)
break;
}
if(cur<0)
break;
mp[vect[cur].second]=1;
cur--;
if(cur<0)
break;
while(mark[vect[cur].second]==1){
cur--;
if(cur<0)
break;
}
if(cur<0)
break;
mp[vect[cur].second]=1;
if(vect[cur].first*(i+2)>mx)
{
mx=vect[cur].first*(i+2);
cnt=i+2;
}
}
// if(i==0)
// cout<<mx<<endl;
}
cout<<mx<<" "<<cnt<<"\n";
}
return 0;
}