#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int inf=2e9, MX=300010;
struct edge{
ll x=1, y=0;
bool operator > (const edge &e) const {
return y*e.x>e.y*x;
}
bool operator == (const edge &e) const {
return y*e.x==e.y*x;
}
};
edge E[MX];
struct node{
int idx;
bool operator > (const node &nd) const {
int a=idx, b=nd.idx;
ll p=E[a].y*E[b].x, q=E[b].y*E[a].x;
return p>q || (p==q && a > b);
}
};
set<int> S1;
set<node, greater<node>> S2;
int n;
ll X[MX], Y[MX];
ll c;
int gcd(int x, int y){
if(y==0) return x;
return gcd(y,x%y);
}
inline ll area(int l, int r){
return (X[r]-X[l])*(Y[l]+Y[r]);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n>>c; c*=2;
for(int i=1; i<=n; i++) cin>>X[i];
for(int i=1; i<=n; i++) cin>>Y[i];
for(int i=1; i<n; i++){
edge e;
e.x=X[i+1]-X[i];
e.y=Y[i+1]-Y[i];
E[i]=e;
}
for(int i=1; i<n; i++){
S1.insert(i);
S2.insert({i});
}
while(true){
int i=S2.begin()->idx;
if(i==1) break;
int j=*prev(S1.find(i));
int k=n;
auto it=S1.find(i);
if(next(it)!=S1.end()) k=*next(it);
ll now=area(j,k)-area(j,i)-area(i,k);
if(now>c) break;
// cout<<"POINTS: "<<j<<' '<<i<<' '<<k<<'\n';
c-=now;
S1.erase(i), S2.erase({i});
S1.erase(j), S2.erase({j});
edge g; g.x=E[i].x+E[j].x, g.y=E[i].y+E[j].y;
E[j]=g; S1.insert(j), S2.insert({j});
// cout<<S1.size()<<", "<<S2.size()<<'\n';
}
{
edge ans=E[S2.begin()->idx];
int x=ans.x, y=ans.y, g=gcd(x,y);
cout<<y/g<<"/"<<x/g<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
644 KB |
Output is correct |
6 |
Correct |
4 ms |
740 KB |
Output is correct |
7 |
Correct |
3 ms |
740 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
3 ms |
596 KB |
Output is correct |
5 |
Correct |
4 ms |
644 KB |
Output is correct |
6 |
Correct |
4 ms |
740 KB |
Output is correct |
7 |
Correct |
3 ms |
740 KB |
Output is correct |
8 |
Correct |
3 ms |
740 KB |
Output is correct |
9 |
Correct |
759 ms |
38224 KB |
Output is correct |
10 |
Correct |
788 ms |
38224 KB |
Output is correct |
11 |
Execution timed out |
1516 ms |
38224 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |