Knot Puzzle
时间限制: 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.
If it is possible to untie all of the knots, print Possible.
样例输入 Copy
3 50
30 20 10
样例输出 Copy
Possible
提示
If the knot 1 is untied first, the knot 2 will become impossible to untie.
题目就是让你剪n-1个结点,每次选取的区间长度不能少于 l ,也就是说只要有两条相邻的线总长 >= l ,那么这个两条线之间的节点就可以放在最后剪,每次选取的区间都包含这两条线,这样就可以都剪完了。
比较水,想出来代码就很简单了。
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#define X first
#define Y second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=100010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n,l;
int a[N],mx;
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d%d",&n,&l);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=2;i<=n;i++)
{
if(mx<a[i]+a[i-1])
mx=a[i]+a[i-1];
}
if(mx>=l) puts("Possible");
else puts("Impossible");
return 0;
}