Problem:
Problem G:
Telescope
Dr. Extreme experimentally made an extremely precise telescope to investigate extremely curi- ous phenomena at an extremely distant place. In order to make the telescope so precise as to investigate phenomena at such an extremely distant place, even quite a small distortion is not allowed. However, he forgot the influence of the internal gas affected by low-frequency vibration of magnetic flux passing through the telescope. The cylinder of the telescope is not affected by the low-frequency vibration, but the internal gas is.
The cross section of the telescope forms a perfect circle. If he forms a coil by putting extremely thin wire along the (inner) circumference, he can measure (the average vertical component of) the temporal variation of magnetic flux:such measurement would be useful to estimate the influence. But points on the circumference at which the wire can be fixed are limited; furthermore, the number of special clips to fix the wire is also limited. To obtain the highest sensitivity, he wishes to form a coil of a polygon shape with the largest area by stringing the wire among carefully selected points on the circumference.
Your job is to write a program which reports the maximum area of all possible
m
-polygons (polygons with exactly
m
vertices) each of whose vertices is one of the
n
points given on a circumference with a radius of 1. An example of the case
n
= 4 and
m
= 3 is illustrated below.
In the figure above, the equations such as "
p
1
= 0.0" indicate the locations of the
n
given points, and the decimals such as "1.000000" on
m
-polygons indicate the areas of
m
-polygons.
Parameter
p
i
denotes the location of the
i
-th given point on the circumference (1 ≤
i
≤
n
). The location
p
of a point on the circumference is in the range 0 ≤
p
< 1, corresponding to the range of rotation angles from 0 to 2
π
radians. That is, the rotation angle of a point at
p
to the point at 0 equals 2
π
radians. (
π
is the circular constant 3.14159265358979323846....)
You may rely on the fact that the area of an isosceles triangle ABC (AB = AC = 1) with an interior angle BAC of
α
radians (0 <
α
<
π
) is (1/2)sin
α
, and the area of a polygon inside a circle with a radius of 1 is less than
π
.
Input
The input consists of multiple subproblems followed by a line containing two zeros that indicates the end of the input. Each subproblem is given in the following format.
n m
p
1
p
2
...
p
n
n
is the number of points on the circumference (3 ≤
n
≤ 40).
m
is the number of vertices to form
m
-polygons (3 ≤
m
≤
n
). The locations of
n
points,
p
1
,
p
2
,...,
p
n
, are given as decimals and they are separated by either a space character or a newline. In addition, you may assume that 0 ≤
p
1
<
p
2
< ... <
p
n
< 1.
Output
For each subproblem, the maximum area should be output, each in a separate line. Each value in the output may not have an error greater than 0.000001 and its fractional part should be represented by 6 decimal digits after the decim
...(truncated)

Submitted solutions:

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

using R = double;
R x[41][41][41], dp[41][41][41], area[41][41][41];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    constexpr R PI = acos(-1);

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(!n) break;
        vector<R> p(n);
        REP(i, n) cin >> p[i], p[i] *= 2*PI;

        REP(i, n) FOR(j, i, n) FOR(k, j, n) {
            area[i][j][k] = (sin(p[j]-p[i]) + sin(p[k]-p[j]) + sin(p[i]-p[k]))/2;
        }

        REP(i, 41) REP(j, 41) REP(k, 41) dp[i][j][k] = -LLINF;
        REP(i, 41) REP(j, 41) dp[i][j][2] = 0;

        R ans = -LLINF;
        REP(l, n) FOR(cnt, 2, m) FOR(r, l+1, n) FOR(i, r+1, n) {
            if(dp[l][r][cnt] == -LLINF) continue;
            chmax(dp[l][i][cnt+1], dp[l][r][cnt] + area[l][r][i]);
            if(cnt+1 <= m) chmax(ans, dp[l][i][cnt+1]);
        }

        cout << fixed << setprecision(6) << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4548
final_rank: 8

code_snippet: #include <bits/stdc++.h>

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

using R = double;
R x[41][41][41], dp[41][41][41], area[41][41][41];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    constexpr R PI = acos(-1);

    while(1) {
        ll n, m;
        cin >> n >> m;
        if(!n) break;
        vector<R> p(n);
        REP(i, n) cin >> p[i], p[i] *= 2*PI;

        REP(i, n) FOR(j, i, n) FOR(k, j, n) {
            area[i][j][k] = (sin(p[j]-p[i]) + sin(p[k]-p[j]) + sin(p[i]-p[k]))/2;
        }

        REP(i, 41) REP(j, 41) REP(k, 41) dp[i][j][k] = -LLINF;
        REP(i, 41) REP(j, 41) dp[i][j][2] = 0;

        R ans = -LLINF;
        REP(sp, n) FOR(cnt, 2, m) FOR(lp, sp+1, n) FOR(np, lp+1, n) {
            if(dp[sp][lp][cnt] == -LLINF) continue;
            chmax(dp[sp][np][cnt+1], dp[sp][lp][cnt] + area[sp][lp][np]);
            if(cnt+1 <= m) chmax(ans, dp[sp][np][cnt+1]);
        }

        cout << fixed << setprecision(6) << ans << endl;
    }

    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 4536
final_rank: 7

code_snippet: #include <iostream>
#include <vector>
#include <complex>
#include <cmath>
using namespace std;
using D = double;
using P = complex<D>;
constexpr D pi = acos(-1);

D cross(const P &a, const P &b){ return a.real()*b.imag()-a.imag()*b.real();}

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector<D> A(n);
    for(int i = 0; i < n; ++i){
      cin >> A[i];
    }
    D ans = 0;
    for(int i = 0; i < n; ++i){
      vector<vector<D>> dp(n,vector<D>(m+1,0));
      for(int j = i+1; j < n; ++j){
        for(int k = i+1; k < j; ++k){
          for(int l = 2; l < m; ++l){
            P a = polar(1.,2*pi*A[i]), b = polar(1.,2*pi*A[k]), c = polar(1.,2*pi*A[j]);
            D s = abs(cross(b-a,c-a))/2;
            dp[j][l+1] = max(dp[k][l] + s, dp[j][l+1]);
            if(l+1 == m) ans = max(ans,dp[j][l+1]);
          }
        }
      }
    }
    printf("%.6f\n",ans);
  }
}
accuracy: 1
time_ms: 290
memory_kb: 3632
final_rank: 14

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
typedef long double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

bool eq(ld a, ld b) {
	return (abs(a - b) < eps);
}

class Line {
public:
	Point a, b;
};
class Circle {
public:
	Point p; ld r;
};

ld dot(Point a, Point b) {
	return real(conj(a)*b);
}
ld cross(Point a, Point b) {
	return imag(conj(a)*b);
}
namespace std {
	bool operator<(const Point &lhs, const Point &rhs) {
		return lhs.real() == rhs.real() ? lhs.imag() < rhs.imag() : lhs.real() < rhs.real();
	}
}
Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}

int ccw(Point a, Point b, Point c) {
	b -= a; c -= a;
	if (cross(b, c) > eps)return 1;//a,b,cが反時計回り
	if (cross(b, c) < -eps)return -1;//a,b,cが時計回り
	if (dot(b, c) < 0)return 2;//c,a,bの順に一直線
	if (norm(b) < norm(c))return -2;//a,b,cの順に一直線
	return 0;//a,c,bの順に一直線
}
bool isis_ll(Line l, Line m) {
	return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a; Point tv = t.b - t.a;
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

//直線lに幅dをつける
vector<Line> make_w(Line l, ld d) {
	Point dif = l.b - l.a;
	dif = dif*Point{0, 1};
	dif = dif * (d / abs(dif));
	vector<Line> ret;
	for (int id = 1; id >= -1; id -= 2) {
		Point a = l.a + dif * (ld)id;
		Point b = l.b + dif * (ld)id;
		ret.push_back({ a,b });
	}
	return ret;
}

typedef vector<Point> polygon;
polygon ConvexHull(polygon p) {
	int n = p.size();
	int k = 0;
	sort(p.begin(), p.end());
	polygon ch(2 * n);
	for (int i = 0; i < n; ch[k++] = p[i++]) {
		while (k >= 2 && ccw(ch[k - 2], ch[k - 1], p[i]) <= 0)--k;
	}
	for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = p[i--]) {
		while (k >= t && ccw(ch[k - 2], ch[k - 1], p[i]) <= 0)--k;
	}
	ch.resize(k - 1);
	return ch;
}
polygon convex_cut(const polygon &p, Line l) {
	vector<Point> ret;
	rep(i, p.size()) {
		Point a = p[i], b = p[(i + 1) % p.size()];
		if (ccw(l.a, l.b, a) != -1)ret.push_back(a);
		if (ccw(l.a, l.b, a)*ccw(l.a, l.b, b)<0) {
			ret.push_back(is_ll({ a,b }, l));
		}
	}
	return ret;
}
ld area(const polygon &p){
	ld ret = 0;
	int n = p.size();
	rep(j, n)ret += cross(p[j], p[(j + 1) % n]);
	return ret / 2.0;
}
ld max_distance(const polygon &p) {
	//assert(p.size()>1);
	polygon g = ConvexHull(p);
	int n = g.size(), a = 0, b = 1;
	ld ret = abs(g[0] - g[1]);
	while (a < n) {
		Point p1 = g[a%n], p2 = g[(a + 1) % n];
		Point q1 = g[b%n], q2 = g[(b + 1) % n];
		if (arg((p2 - p1) / (q1 - q2)) > 0)++b; else ++a;
		ret = max(ret, abs(p1 - q1));
	}
	return ret;
}

vector<Point> is_cc(Circle c1, Circle c2) {
	vector<Point> res;
	ld d = abs(c1.p - c2.p);
	ld rc = (d*d + c1.r*c1.r - c2.r*c2.r) / (2 * d);
	ld dfr = c1.r*c1.r - rc * rc;
	if (abs(dfr) < eps)dfr = 0.0;
	if (dfr < 0.0)return res;
	ld rs = sqrt(dfr);
	Point diff = (c2.p - c1.p) / d;
	res.push_back(c1.p + diff * Point(rc, rs));
	if (dfr != 0.0)res.push_back(c1.p + diff * Point(rc, -rs));
	return res;
}
bool in_Circle(Circle a, Circle b) {
	ld dist = abs(b.p - a.p);
	return dist < b.r - a.r+eps;
}

ld calc(ld t) {
	ld theta = pi*t;
	return sin(theta)*cos(theta);
}
int n, m;
void solve() {
	vector<ld> p(n);
	rep(i, n)cin >> p[i];
	ld ans = -mod;
	rep(i, n) {
		vector<vector<ld>> dp(n);
		rep(j, n)dp[j].resize(m,-mod);
		dp[0][0] = 0;
		rep1(j, n - 1) {
			int id = (i + j)%n;
			rep(k, j) {
				int pid = (i + k) % n;
				rep(l, m-1) {
					ld dif = p[id] - p[pid];
					if (dif < 0)dif += 1;
					dp[j][l + 1] = max(dp[j][l + 1], dp[k][l] + calc(dif));
				}
			}
		}
		rep(j, n) {
			int id = (i + j) % n;
			ld dif = p[i] - p[id];
			if (dif < 0)dif += 1;
			ld sum = calc(dif) + dp[j][m - 1];
			ans = max(ans, sum);
			/*if (sum > 0.731010) {
				cout << i << " " << j << " " << dp[j][m-1]<<" "<<calc(dif) << endl;
			}*/
		}
	}
	cout << ans << endl;
	//cout << calc(0.24) << endl;
	/*rep(i, 40) {
		ld u = 0.002*i;
			cout << u << " " << calc(u) << endl;
	}*/
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(6);
	int t = 1;
	while (cin >> n>>m, n) {
		solve();
	}
	//solve();
	//stop
	return 0;
}
accuracy: 1
time_ms: 1050
memory_kb: 3564
final_rank: 18

code_snippet: #include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}

namespace Geometry{
    typedef long double D;
    typedef complex<long double> P;
    typedef pair<P,D> C;
    
    const D EPS=1e-9;
    const D PI=asin(1)*2;
    const D INF=1e18;
    
    const static bool comp(const P &p1,const P &p2){return p1.real()==p2.real()?p1.imag()<p2.imag():p1.real()<p2.real();}
    
    D dot(P p1,P p2){return p1.real()*p2.real()+p1.imag()*p2.imag();}
    
    D cross(P p1,P p2){return p1.real()*p2.imag()-p1.imag()*p2.real();}
    
    P project(P vec,P x){return vec*(x/vec).real();}
    
    P project(P p1,P p2,P x){return p1+project(p2-p1,x-p1);}
    
    P reflect(P vec,P x){return vec*conj(x/vec);}
    
    P reflect(P p1,P p2,P x){return p1+reflect(p2-p1,x-p1);}
    
    bool intersectSL(P p1,P p2,P vec){vec/=abs(vec); p1/=vec; p2/=vec; return (p1.imag()<EPS && p2.imag()>-EPS) || (p1.imag()>-EPS && p2.imag()<EPS);}
    
    bool intersectSL(P p1,P p2,P p3,P p4){return intersectSL(p1-p4,p2-p4,p3-p4);}
    
    bool intersectSS(P p1,P p2,P p3,P p4){return (dot(p2-p1,p3-p1)<-EPS && dot(p2-p1,p4-p1)<-EPS) || (dot(p1-p2,p3-p2)<-EPS && dot(p1-p2,p4-p2)<-EPS)?false:intersectSL(p1,p2,p3,p4) && intersectSL(p3,p4,p1,p2);}
    
    D distLP(P vec,P x){return abs((x/vec).imag())*abs(vec);}
    
    D distLP(P p1,P p2,P x){return distLP(p2-p1,x-p1);}
    
    D distSP(P p1,P p2,P x){return dot(p2-p1,x-p1)<-EPS?abs(x-p1):dot(p1-p2,x-p2)<-EPS?abs(x-p2):distLP(p1,p2,x);}
    
    D distSS(P p1,P p2,P p3,P p4){return intersectSS(p1,p2,p3,p4)?0.0:min(min(distSP(p1,p2,p3),distSP(p1,p2,p4)),min(distSP(p3,p4,p1),distSP(p3,p4,p2)));}
    
    P crosspointLL(P p1,P p2,P vec){return abs(cross(p2-p1,vec))<EPS?vec:vec*cross(p2-p1,p2)/cross(p2-p1,vec);}
    
    P crosspointLL(P p1,P p2,P p3,P p4){return p4+crosspointLL(p1-p4,p2-p4,p3-p4);}
    
    P crosspointSS(P p1,P p2,P p3,P p4){return distSP(p1,p2,p3)<EPS?p3:distSP(p1,p2,p4)<EPS?p4:crosspointLL(p1,p2,p3,p4);}
    
    bool intersectShL(P p1,P p2,P vec){vec/=abs(vec); return intersectSL(p1,p2,vec) && crosspointLL(p1/vec,p2/vec,vec/vec).real()>-EPS;}
    
    bool intersectShL(P p1,P p2,P p3,P p4){return intersectShL(p1-p3,p2-p3,p4-p3);}
    
    //1::in,0::on edge,-1::out
    int contain(const vector<P> &poly,const P &p){
        vector<P> A={{65537,96847},{-24061,6701},{56369,-86509},{-93763,-78049},{56957,10007}};
        vector<bool> cnt(5,false);
        for(int i=1;i<=poly.size();i++){
            if(distSP(poly[i-1],poly[i%poly.size()],p)<EPS){return 0;}
            for(int j=0;j<5;j++){
                if(intersectShL(poly[i-1],poly[i%poly.size()],p,p+A[j])){cnt[j]=!cnt[j];}
            }
        }
        int in=0;
        for(int j=0;j<5;j++){if(cnt[j]){in++;}}
        return in>=3?1:-1;
    }
    
    vector<P> convexcut(const vector<P> &poly,P p1,P p2){
        vector<P> ret;
        for(int i=1;i<=poly.size();i++){
            if(cross(p2-p1,poly[i-1]-p1)>-EPS){ret.push_back(poly[i-1]);}
            if(intersectSL(poly[i-1],poly[i%poly.size()],p1,p2) && distLP(p1,p2,poly[i-1])>EPS && distLP(p1,p2,poly[i%poly.size()])>EPS){ret.push_back(crosspointLL(poly[i-1],poly[i%poly.size()],p1,p2));}
        }
        return ret;
    }
    
    D area(const vector<P> &poly){
        D ans=0;
        for(int i=2;i<poly.size();i++){ans+=cross(poly[i-1]-poly[0],poly[i]-poly[0]);}
        return abs(ans)/2;
    }
    
    vector<P> convexhull(vector<P> pts){
        vector<P> ret;
        sort(pts.begin(),pts.end(),comp);
        for(auto &I:pts){
            if(!ret.empty() && I==ret.back()){continue;}
            while(ret.size()>=2 && cross(ret.back()-ret[ret.size()-2],I-ret.back())<-EPS){ret.pop_back();}
            ret.push_back(I);
        }
        reverse(pts.begin(),pts.end());
        for(auto &I:pts){
            if(!ret.empty() && I==ret.back()){continue;}
            while(ret.size()>=2 && cross(ret.back()-ret[ret.size()-2],I-ret.back())<-EPS){ret.pop_back();}
            ret.push_back(I);
        }
        if(ret[0]==ret.back()){ret.pop_back();}
        return ret;
    }
    
    //4::seperate,3::circumscribe,2::intersect,1::inscribe,0::contain,-1::same
    int intersectCC(C c1,C c2){
        D d=abs(c1.F-c2.F),r=c1.S+c2.S,dif=abs(c2.S-c1.S);
        if(d<EPS && dif<EPS){return -1;}
        if(d-r>EPS){return 4;}
        if(d-r>-EPS){return 3;}
        if(d-dif>EPS){return 2;}
        if(d-dif>-EPS){return 1;}
        return 0;
    }
    
    vector<P> crosspointLC(P p1,P p2,C c){
        vector<P> ret;
        P pr=project(p1,p2,c.F);
        D d=distLP(p1,p2,c.F);
        if(d-c.S>EPS){return ret;}
        if(d-c.S>-EPS){ret.push_back(pr); return ret;}
        P vec=p2-p1; vec*=sqrt(c.S*c.S-d*d)/abs(vec);
        ret.push_back(pr-vec);
        ret.push_back(pr+vec);
        return ret;
    }
    
    vector<P> crosspointSC(P p1,P p2,C c){
        vector<P> ret;
        for(auto &I:crosspointLC(p1,p2,c)){if(distSP(p1,p2,I)<EPS){ret.push_back(I);}}
        return ret;
    }
    
    vector<P> crosspointCC(C c1,C c2){
        vector<P> ret;
        P vec=c2.F-c1.F;
        D base=(c1.S*c1.S+norm(vec)-c2.S*c2.S)/(2*abs(vec));
        D h=sqrt(c1.S*c1.S-base*base);
        vec/=abs(vec);
        ret.push_back(c1.F+vec*P(base,-h));
        ret.push_back(c1.F+vec*P(base,h));
        return ret;
    }
    
    vector<P> tangentCP(C c,P p){return crosspointCC(c,C(p,sqrt(norm(c.F-p)-c.S*c.S)));}
    
    vector<pair<P,P>> tangentCC(C c1,C c2){
        vector<pair<P,P>> ret;
        P d=c2.F-c1.F;
        for(D i:{-1,1}){
            D r=c1.S+c2.S*i;
            if(intersectCC(c1,c2)>i+1){
                for(P s:{-1i,1i}){
                    P p=r+s*sqrt(norm(d)-norm(r));
                    ret.push_back({c1.F+d*c1.S/norm(d)*p,c2.F-d*i*c2.S/norm(d)*p});
                }
            }
        }
        return ret;
    }
    
    D area(const vector<P> &poly,C c){
        D ret=0;
        for(int i=0;i<poly.size();i++){
            P a=poly[i]-c.F,b=poly[(i+1)%poly.size()]-c.F;
            if(abs(a)<c.S+EPS && abs(b)<c.S+EPS){ret+=cross(a,b);}
            else{
                vector<P> A=crosspointSC(a,b,{0,c.S});
                if(A.empty()){ret+=c.S*c.S*arg(b/a);}
                else{
                    ret+=(abs(a)<c.S?cross(a,A[0]):c.S*c.S*arg(A[0]/a));
                    ret+=(abs(b)<c.S?cross(A.back(),b):c.S*c.S*arg(b/A.back()));
                    ret+=cross(A[0],A.back());
                }
            }
        }
        return abs(ret)/2;
    }
    
    //反時計回り
    D diameter(const vector<P> &poly){
        D ret=0;
        ll l=0,r=0,n=poly.size();
        if(n==2){return abs(poly[0]-poly[1]);}
        for(int i=0;i<n;i++){
            if(comp(poly[l],poly[i])){l=i;}
            if(comp(poly[i],poly[r])){r=i;}
        }
        ll sl=r,sr=l;
        while(sl!=l || sr!=r){
            ret=max(ret,abs(poly[r]-poly[l]));
            if(cross(poly[(l+1)%n]-poly[l],poly[(r+1)%n]-poly[r])<0){(++l)%=n;}
            else{(++r)%=n;}
        }
        return ret;
    }
    
    D closestpair(vector<P> pt){
        sort(pt.begin(),pt.end(),comp);
        D ret=INF;
        for(ll i=1;i<pt.size();i<<=1){
            for(ll j=0;i+j<pt.size();j+=i*2){
                ll m=i+j;
                vector<P> R;
                D l=-INF,r=INF;
                for(ll k=j;k<m;k++){l=max(l,pt[k].real());}
                for(ll k=0;m+k<pt.size() && k<i;k++){r=min(r,pt[m+k].real());}
                for(ll k=0;m+k<pt.size() && k<i;k++){if(pt[m+k].real()-l<ret){R.push_back(pt[m+k]);}}
                ll idx=0;
                for(ll k=j;k<m;k++){
                    if(r-pt[k].real()>ret){continue;}
                    while(idx<R.size() && pt[k].imag()-R[idx].imag()>ret){idx++;}
                    for(ll n=idx;n<R.size() && R[n].imag()-pt[k].imag()<ret;n++){ret=min(ret,abs(R[n]-pt[k]));}
                }
                inplace_merge(pt.begin()+j,pt.begin()+m,j+i*2<pt.size()?pt.begin()+j+2*i:pt.end(),[](const P &a,const P &b){return a.imag()==b.imag()?a.real()<b.real():a.imag()<b.imag();});
            }
        }
        return ret;
    }
    
    istream & operator >> (istream &i,P &p){D x,y; i>>x>>y; p={x,y}; return i;}
    istream & operator >> (istream &i,C &p){D x,y; i>>x>>y>>p.S; p.F={x,y}; return i;}
};

using namespace Geometry;


D cul(const vector<P> &A,ll s,ll n,ll m){
    vector<vector<D>> dp(n,vector<D>(m,-E));
    dp[s][0]=0;
    for(ll i=s+1;i<n;i++){
        for(int j=1;j<m;j++){
            for(int k=0;k<i;k++){dp[i][j]=max(dp[i][j],dp[k][j-1]+cross(A[k],A[i]));}
        }
    }
    D ret=-E;
    for(ll i=s+1;i<n;i++){ret=max(ret,dp[i].back()+cross(A[i],A[s]));}
    return ret;
}


int main(){
    ll n,m;
    while(cin>>n>>m,n){
        vector<D> R(n);
        cin>>R;
        vector<P> A(n);
        for(int i=0;i<n;i++){A[i]=polar((D)1,R[i]*2*PI);}
        D ret=0;
        for(int i=0;i<n;i++){ret=max(ret,cul(A,i,n,m));}
        cout<<fixed<<setprecision(6)<<ret/2<<endl;
    }
    
    
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3632
final_rank: 4

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e18;
const double PI = acos(-1);
typedef complex<double> P;
typedef vector<P> VP;
#define X real()
#define Y imag()

double cross(P a, P b){
    return (conj(a)*b).Y;
}
double gettriarea(P a, P b, P c){
    return abs(cross(b-a, c-a)) /2;
}

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0) break;

        VP p(n);
        for(int i=0; i<n; i++){
            double d;
            cin >> d;
            p[i] = P(1, 0) *P(cos(d*2*PI), sin(d*2*PI));
        }
        double ans = 0;
        for(int sp=0; sp<n; sp++){
            p.push_back(p[0]);
            p.erase(p.begin());
            vector<vector<double> > dp(n+1, vector<double>(n+1, 0));
            for(int cp=2; cp<n; cp++){
                for(int cn=3; cn<=cp +1; cn++){
                    for(int lp=cn-2; lp<cp; lp++){
                        dp[cp][cn] = max(dp[cp][cn], dp[lp][cn-1] +gettriarea(p[0], p[lp], p[cp]));
                    }
                }
            }
            for(int i=0; i<n; i++){
                ans = max(ans, dp[i][m]);
            }
        }
        cout << fixed << setprecision(6);
        cout << ans << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3488
final_rank: 3

code_snippet: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
const ld pi=acos(-1.0);

ld solve(int N, int M, vector<ld>ps) {
	vector<vector<vector<ld>>>dp(N+1,vector<vector<ld>>(M+1,vector<ld>(N,-1e8)));
	dp[1][1][0]=0;
	for (int now = 1; now < N; ++now) {
		for (int used_cnt = 0; used_cnt <= M; ++used_cnt) {
			for (int pre_use_id = 0; pre_use_id < now; ++pre_use_id) {
				dp[now+1][used_cnt][pre_use_id]=max(dp[now+1][used_cnt][pre_use_id],
					dp[now][used_cnt][pre_use_id]);

				if (used_cnt != M) {

					ld plus = 0.5*(sin(2 * pi*(ps[now] - ps[pre_use_id])));
					dp[now + 1][used_cnt + 1][now] = max(
						dp[now + 1][used_cnt + 1][now],
						dp[now][used_cnt][pre_use_id] + plus);
				}
			}
		}
	}
	ld ans=0;
	for (int pre_use_id = 0; pre_use_id < N; ++pre_use_id) {

		ld plus = 0.5*(sin(2 * pi*(ps[0] - ps[pre_use_id])));
		ans=max(ans,dp[N][M][pre_use_id]+plus);
	}
	return ans;
}

int main() {
	while (true) {
		int N, M; cin >> N >> M;
		if(!N)break;
		vector<ld>ps;
		for (int i = 0; i < N; ++i) {
			ld theta; cin >> theta;
			ps.push_back(theta);
		}

		ld ans = 0;
		for (int i = 0; i < N; ++i) {
			rotate(ps.begin(), ps.begin() + 1, ps.end());
			ans = max(ans, solve(N, M, ps));
		}
		cout<<setprecision(6)<<fixed<<ans<<endl;
	}
	

	return 0;
}
accuracy: 1
time_ms: 1200
memory_kb: 3768
final_rank: 20

code_snippet: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Point{
	double x,y;
};

int N,M;

Point point[40];
double dp[40][40][41];

double calc(int start,int last,int next){
    return fabs((point[start].x*point[last].y-point[last].x*point[start].y)+(point[last].x*point[next].y-point[next].x*point[last].y)+
    		(point[next].x*point[start].y-point[start].x*point[next].y))/2;
}

void func(){

	double tmp;

	for(int i = 0; i < N; i++){
		scanf("%lf",&tmp);
		point[i].x = cos(tmp*2.0*M_PI);
		point[i].y = sin(tmp*2.0*M_PI);
	}

	for(int a = 0; a < 40; a++){
		for(int b = 0; b < 40; b++){
			for(int c = 0; c <= 40; c++)dp[a][b][c] = 0.0;
		}
	}

	double ans = 0.0;

	for(int start = 0; start < N; start++){
		for(int count = 2; count < M; count++){
			for(int last = start; last < N; last++){
				for(int next = last+1; next < N; next++){
					dp[start][next][count+1] = max(dp[start][next][count+1],dp[start][last][count]+calc(start,last,next));

					if(count+1 == M)ans = max(ans,dp[start][next][count+1]);
				}
			}
		}
	}
	printf("%.6lf\n",ans);
}

int main(){

	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		func();
	}

	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4092
final_rank: 5

code_snippet: #include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_N 41
 
const double Pi = acos(-1);
 
double getAngle(double p, double q) {
  // assert(p < q);
   
  return (p-q)*2*Pi;
}
 
#define eps 1e-8
 
double getArea(double p, double q) {
  //cout<<getAngle(p,q)<<endl;
  //if(getAngle(p,q) > 0.5) return fabs(sin(1-getAngle(p, q))/2);
  return (sin(getAngle(p, q))/2);
}
 
int n, m;
double p[MAX_N];
 
double dp[MAX_N][MAX_N][MAX_N];
 
double solve(int idx, int curr, int start) {
  if(idx == m) {
    //if((1+p[start]-p[curr])-0.5 > 0) return -getArea(p[curr], p[start]);
    return getArea(p[start], p[curr]);
  }
  if(curr+1 == n) return -1e9;
  double &res = dp[idx][curr][start];
  if(res != -1) return res;
  for(int i = curr+1; i < n; i++) {
    res = max(res, solve(idx+1, i, start) + getArea(p[i], p[curr]));
  }
  return res;
}
 
int main() {
  while(cin >> n >> m, n || m) {
    for(int i = 0; i < n; i++) cin >> p[i];
 
    double ans = 0;
    for(int i = 0; i < MAX_N; i++)
      for(int j = 0; j < MAX_N; j++)
    for(int k = 0; k < MAX_N; k++)
      dp[i][j][k] = -1;
     
    for(int i = 0; i < n; i++) {
      ans = max(ans, solve(1, i, i));
    }
    printf("%.6f\n", ans);
  }
   
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4004
final_rank: 11

code_snippet: #include<bits/stdc++.h>
 
using namespace std;
 
typedef complex<double> P;
 
int n,m;
double p[50];
 
double cal(int a,int b,int c){
 
  double res;
 
  P s=P(cos(p[a]),sin(p[a])),t=P(cos(p[b]),sin(p[b])),u=P(cos(p[c]),sin(p[c]));
 
  double aa=abs(s-t),bb=abs(t-u),cc=abs(u-s);
  double ss=(aa+bb+cc)/2;
 
  res=sqrt(ss*(ss-aa)*(ss-bb)*(ss-cc));
 
  return res;
}
 
int main(){
 
 
  while(cin>>n>>m,n){
 
    for(int i=0;i<n;i++){
      cin>>p[i];
      p[i]*=2*M_PI;
    }
 
  double dp[50][50][50]={};
   
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=2;k<m;k++)
    for(int l=j+1;l<n;l++){
      dp[i][l][k+1]=max(dp[i][l][k+1],dp[i][j][k]+cal(i,j,l));
    }
 
  double ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)ans=max(ans,dp[i][j][m]);
   
  printf("%.6f\n",ans);
   
  }
 
 
   
  return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 4560
final_rank: 15

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX_N 41

const double Pi = acos(-1);

double getAngle(double p, double q) {
  // assert(p < q);
  
  return (p-q)*2*Pi;
}

#define eps 1e-8

double getArea(double p, double q) {
  //cout<<getAngle(p,q)<<endl;
  //if(getAngle(p,q) > 0.5) return fabs(sin(1-getAngle(p, q))/2);
  return (sin(getAngle(p, q))/2);
}

int n, m;
double p[MAX_N];

double dp[MAX_N][MAX_N][MAX_N];

double solve(int idx, int curr, int start) {
  if(idx == m) {
    //if((1+p[start]-p[curr])-0.5 > 0) return -getArea(p[curr], p[start]);
    return getArea(p[start], p[curr]);
  }
  if(curr+1 == n) return -1e9;
  double &res = dp[idx][curr][start];
  if(res != -1) return res;
  for(int i = curr+1; i < n; i++) {
    res = max(res, solve(idx+1, i, start) + getArea(p[i], p[curr]));
  }
  return res;
}

int main() {
  while(cin >> n >> m, n || m) {
    for(int i = 0; i < n; i++) cin >> p[i];

    double ans = 0;
    for(int i = 0; i < MAX_N; i++)
      for(int j = 0; j < MAX_N; j++)
	for(int k = 0; k < MAX_N; k++)
	  dp[i][j][k] = -1;
    
    for(int i = 0; i < n; i++) {
      ans = max(ans, solve(1, i, i));
    }
    printf("%.6f\n", ans);
  }
  
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 4000
final_rank: 10

code_snippet: #include<bits/stdc++.h>

using namespace std;

typedef complex<double> P;

int n,m;
double p[50];

double cal(int a,int b,int c){

  double res;

  P s=P(cos(p[a]),sin(p[a])),t=P(cos(p[b]),sin(p[b])),u=P(cos(p[c]),sin(p[c]));

  double aa=abs(s-t),bb=abs(t-u),cc=abs(u-s);
  double ss=(aa+bb+cc)/2;

  res=sqrt(ss*(ss-aa)*(ss-bb)*(ss-cc));

  return res;
}

int main(){


  while(cin>>n>>m,n){

    for(int i=0;i<n;i++){
      cin>>p[i];
      p[i]*=2*M_PI;
    }

  double dp[50][50][50]={};
  
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=2;k<m;k++)
	for(int l=j+1;l<n;l++){
	  dp[i][l][k+1]=max(dp[i][l][k+1],dp[i][j][k]+cal(i,j,l));
	}

  double ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)ans=max(ans,dp[i][j][m]);
  
  printf("%.6f\n",ans);
  
  }


  
  return 0;
}
accuracy: 1
time_ms: 410
memory_kb: 4572
final_rank: 16

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int n, m;
double p[88];
double dp[44][44][44];

const double Pi = acos(-1);
double area(int a, int b) {
  return sin((p[b]-p[a])*2*Pi)/2;
}

double solve(int fr, int la, int cnt) {
  if(cnt == m) return (la-fr < 0.5 ? -1 : 1)*area(la, n+fr);
  if(la == n-1) return -DBL_MAX/3;
  double &res = dp[fr][la][cnt];
  if(res != -DBL_MAX/3) return res;
  res = -DBL_MAX/5;
  reps(i, la+1, n) {
    chmax(res, solve(fr, i, cnt+1)+area(la, i));
  }
  return res;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(6);

  while(cin >> n >> m, n || m) {
    rep(i, n) cin >> p[i];
    rep(i, n) p[n+i] = p[i]+1;
    rep(i, 44) rep(j, 44) rep(k, 44) dp[i][j][k] = -DBL_MAX/3;
    double ans = 0;
    rep(i, n) chmax(ans, solve(i, i, 1));
    cout << ans << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4172
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int long long
struct Point{
  double x,y;
  Point(){}
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point a){return Point(x+a.x,y+a.y);}
  Point operator-(Point a){return Point(x-a.x,y-a.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
};
typedef Point Vector;
typedef vector<Point> Polygon;
double norm(Point a){
  return a.x*a.x+a.y*a.y;
}
double abs(Point a){
  return sqrt(norm(a));
}
double dot(Point a,Point b){
  return a.x*b.x+a.y*b.y;
}
double cross(Point a,Point b){
  return a.x*b.y-a.y*b.x;
}
const double PI=3.141592653589793238;
Point trans(double k){
  return Point(cos(k*2*PI),sin(k*2*PI));
}
int n,m;
Polygon p;
double dp[50][50][50];
double dfs(int b,int c,int d){
  if(d==m) return 0;
  if(dp[b][c][d]>=0) return dp[b][c][d];
  double res=0;
  for(int a=c;a!=b;a=(a+1)%n){
    res=max(res,dfs(b,a,d+1)+abs(cross(p[a]-p[b],p[c]-p[b])));
  }
  return dp[b][c][d]=res;
}
signed main(){
  while(cin>>n>>m,n||m){
    p.clear();
    p.resize(n);
    for(int i=0;i<n;i++){
      double k;
      cin>>k;
      p[i]=trans(k);
      //cout<<p[i].x<<" "<<p[i].y<<endl;
    }
    for(int i=0;i<50;i++)
      for(int j=0;j<50;j++)
	for(int k=0;k<50;k++)
	  dp[i][j][k]=-1;
    double ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j) continue;
	ans=max(ans,dfs(i,j,2));
      }
    }
    printf("%.6f\n",ans/2.0);
  }
  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 4396
final_rank: 13

code_snippet: #include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for(int i = a; i < (int)b; i++)
#define pb push_back
#define mp make_pair
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
const int INF = 1<<28;
const ll MOD = 1000000007;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

double area(double a, double b, double c) {
	return sin((b-a)*2*M_PI)/2 + sin((c-b)*2*M_PI)/2 + sin((a-c)*2*M_PI)/2;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	while(cin >> n >> m, n|m) {
		double dp[40][40][40] = {};
		double p[n];
		REP(i, n)
			cin >> p[i];
		REP(i, m-2) {
			REP(j, n-2) {
				FOR(k, j+2, n) {
					FOR(l, j+1, k) {
						if(i)
							dp[i][j][k] = max(dp[i][j][k], dp[i-1][j][l] + area(p[j], p[l], p[k]));
						else
							dp[i][j][k] = max(dp[i][j][k], area(p[j], p[l], p[k]));
					}
				}
			}
		}
		double ans = -1;
		REP(i, n) REP(j, n)
			ans = max(ans, dp[m-3][i][j]);
		cout << fixed << setprecision(6) << ans << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 1864
final_rank: 12

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define MAX 45
#define PI acos(-1)
#define INF (1<<29)
typedef pair<double, double> P;

int N, M;
double memo[MAX][MAX][MAX];
vector<double> x, y;

double area(int a, int b, int c)
{
    vector<P> p(3);
    p[0] = P(x[a], y[a]);
    p[1] = P(x[b], y[b]);
    p[2] = P(x[c], y[c]);   
    
    double res = 0;
    for (int i = 1; i < 4; i++) {
	res += (p[i%3].first - p[i-1].first) * (p[i%3].second + p[i-1].second);
    }
    res /= 2.0;
    return abs(res);
}

double get_max_area(int L, int R, int m)
{
    if (m == M) {
        return 0;
    }    
    double &res = memo[L][R][m];
    if (res != -1) {
        return res;
    }
    for (int i = R+1; i < N; i++) {
        res = max(res, get_max_area(L, i, m+1) + area(L, R, i));
    }
    return res;
}

int main()
{
    double p;
    while (cin >> N >> M, N) {
        x.clear(); y.clear();
        x.resize(N); y.resize(N);
        for (int i = 0; i < N; i++) {
            cin >> p;
            p *= (2.0 * PI);
            x[i] = cos(p); y[i] = sin(p);
        }
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    memo[i][j][k] = -1;
                }
            }
        }

        double mx = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                for (int k = j+1; k < N; k++) {
                    mx = max(mx, get_max_area(i, k, 3) + area(i, j, k));
                }
            }
        }
        printf("%.6f\n", mx);
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 4076
final_rank: 6

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

///double dp[44][44];
vector<double> ps;
int N, M;

double const pi = acos(-1);

double triangle(int s, int t, int k) {
  vector<int> idxs = {s, t, k};
  sort(idxs.begin(), idxs.end());

  double a = 2 * pi * ps[idxs[0]];
  double b = 2 * pi * ps[idxs[1]];
  double c = 2 * pi * ps[idxs[2]];

  double ba = b - a;
  double cb = c - b;
  double ac = a - c;

  while(ba < 0) { ba += 2 * pi; }
  while(cb < 0) { cb += 2 * pi; }
  while(ac < 0) { ac += 2 * pi; }

  return (sin(ba) + sin(cb) + sin(ac)) / 2.0;
}

int st;
map<pair<int, int>, double> mp;

double dfs(int curr, int rem) {
  if(rem == 0) { return 0.0; }
  if(N + st - curr + 1 <= 1) { return -100000000; }
  if(mp.find({curr, rem}) != mp.end()) { return mp[{curr, rem}]; }
  auto& ret = mp[{curr, rem}];

  REP(i, curr + 1, N + st) {
    double d = triangle(st % N, curr % N, i % N);
    d += dfs(i, rem-1);
    ret = max(ret, d);
  }
  return ret;
}

int main() {

  for(;cin >> N >> M && (N|M);) {
    ps.clear();
    ps.resize(N);
    rep(i, N) cin >> ps[i];
    sort(ps.begin(), ps.end());
    double ans = -10000000000;
    rep(i, N) {
      mp.clear();
      st = i;
      ans = max(ans, dfs(i, M-1));
    }

    printf("%.6f\n", ans);

  }

  return 0;
}
accuracy: 1
time_ms: 720
memory_kb: 3592
final_rank: 17

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef pair<double,double> P;
double S(double a,double b,double c) {
  double s=(a+b+c)/2;
  return sqrt(s*(s-a)*(s-b)*(s-c));
}
double D(P a,P b) {
  return sqrt((a.first-b.first)*(a.first-b.first)+(a.second-b.second)*(a.second-b.second));
}
double calc(P a,P b, P c) {
  return S(D(a,b),D(a,c),D(b,c));
}
  
double toRad(double agl) {
  return agl*M_PI/180.0;
}
P Q(double e) {
  double w=toRad(360*e);
  return P(sin(w),cos(w));
}

int main() {
  int n,m;
  while(cin >> n >> m && n) {
    P p[n];
    for(int i=0; i<n; i++) {
      double x;
      cin >> x;
      p[i]=Q(x);
    }
    double ans=0;
    for(int i=0; i<n; i++) {
      double dp[n][m+1];
      for(int j=0;j<n;j++)for(int k=0;k<=m;k++)dp[j][k]=-1; 
      for(int j=i+1; j<n; j++) dp[j][2]=0;
      for(int j=i+1; j<n; j++) {
        for(int k=2; k<m; k++) {
          if(dp[j][k]<0) continue;
          for(int l=j+1; l<n; l++) {
            dp[l][k+1]=max(dp[l][k+1],dp[j][k]+calc(p[i],p[j],p[l]));
            if(k+1==m) ans=max(ans,dp[l][k+1]);
          }
        }
      }                                      
    }
    printf("%.6f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 1256
final_rank: 1

code_snippet: #include<bits/stdc++.h>
using namespace std;

typedef complex<double> P;

double dp[41][41][41][41];
double getA[41][41][41];
int nx[41];
const double INF = 1e100;

double cross( P a, P b ){ return a.real() * b.imag() - a.imag() * b.real(); }

int N,M;

P getpos(double p){
  double a = 2*M_PI*p;
  return P( cos(a), sin(a) );
}

void init(const vector<P> pos){
  for(int i=0;i<N;i++) nx[i] = (i+1)%N;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=0;k<N;k++)
        for(int l=0;l<=M;l++)
          dp[i][j][k][l] = -1.0;

  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)
      for(int k=0;k<N;k++)
        getA[i][j][k] = cross( pos[j]-pos[i], pos[k]-pos[i] )/2.0;
      
}


double solve(int a,int b,int c,int m){
  if( abs(dp[a][b][c][m]+1.0) > 0.5 ) return dp[a][b][c][m];
  if( m == M ) return dp[a][b][c][m] = 0.0;
  if( c == a ) return dp[a][b][c][m] = -INF;
  int nc = nx[c];
  return dp[a][b][c][m] = max(  solve( a, c, nc, m+1 ) + getA[a][b][c],
                                 solve( a, b, nc, m ) );    
}

int main(){
  while( cin >> N >> M && (N||M) ){
    vector<P> pos;
    for(int i=0;i<N;i++){
      double p; cin >> p;
      pos.push_back( getpos(p) );
    }
    init(pos);
    double res = 0.0;
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if( i == j ) continue;
        res = max( res, solve( i, j, nx[j], 2 ) );
      }
    }
    printf("%.6lf\n",res);
  }
}
accuracy: 1
time_ms: 110
memory_kb: 23748
final_rank: 19

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
#define MAX_N 45
double PI = acos(-1.0);
double INF = 1e9;

int n,m;
P t[MAX_N];
double dp[MAX_N][MAX_N];

double calc(P s,P t){
  return imag(t*conj(s))/2.0;
}

double solve(int si){
  P a[MAX_N];
  for(int i=0;i<n;i++){
    a[i]=t[(i+si)%n];
  }

  for(int i=0;i<MAX_N;i++)
    for(int j=0;j<MAX_N;j++)
	dp[i][j]=-INF;
  dp[0][1]=0;

  double res=0;

  for(int i=0;i<n;i++){
    for(int j=1;j<m;j++){
      for(int k=i+1;k<n;k++){
	dp[k][j+1]=max(dp[k][j+1],dp[i][j]+calc(a[i],a[k]));
      }
    }
    res=max(res, dp[i][m]+calc(a[i],a[0]));
  }
  return res;
}

int main(){
  while(1){
    cin>>n>>m;
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++){
      double d;
      cin>>d;
      t[i]=P(cos(d*2.0*PI),sin(d*2.0*PI));
    }
    double ans=0;
    for(int i=0;i<n;i++)ans=max(ans,solve(i));
    printf("%.6f\n",ans);
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 1276
final_rank: 2