【想法题】Knot Puzzle @AtCoder Grand Contest 002 C/upcexam5583

时间:2022-11-08 15:24:18

时间限制: 2 Sec 内存限制: 256 MB

题目描述

We have N pieces of ropes, numbered 1 through N. The length of piece i is ai.

At first, for each i(1≤i≤N−1), piece i and piece i+1 are tied at the ends, forming one long rope with N−1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly:

Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N−1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.

Constraints 2≤N≤105 1≤L≤109 1≤ai≤109 All input values are integers.

输入

The input is given from Standard Input in the following format:

N L a1 a2 … an

输出

If it is not possible to untie all of the N−1 knots,

print Impossible.

样例输入

3 50

样例输出

Possible

提示

If the knot 1 is untied first, the knot 2 will become impossible to untie.

题目大意是给你n根绳子通过打结的方式首尾相接成一根绳子,要你解开这个绳子上所有的结,但你每次只能选一根长度大于L的绳子解开其上的一个结。

如果我们把用来组成长绳的n个绳子称作绳元

只要有两个相邻的绳元长度大于L,就可以以这两个绳元为中心从两端解开整根绳子。

#define IN_PC() freopen("C:\\Users\\hz\\Desktop\\in.txt","r",stdin)
#define OUT_PC() freopen("C:\\Users\\hz\\Desktop\\out.txt","w",stdout)
#include <bits/stdc++.h> using namespace std; const int maxn = 100005;
int a[maxn]; int main()
{
// IN_PC();
// OUT_PC();
int n,L;
cin>>n>>L;
for(int i=0;i<n;i++){
scanf("%d",a+i);
}
int flag = 0;
for(int i=1;i<n;i++){
if(a[i-1]+a[i]>=L)flag = 1;
}
printf("%s\n",flag?"Possible":"Impossible");
return 0;
}