Cutting Codeforces Round #493 (Div. 2)
阿新 • • 發佈:2019-01-22
string bre cut fine using ons sort its vector
#include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #include<vector> #include<stack> #include<bitset> #include<cstdlib> #include<cmath> #include<set> #include<list> #include<deque> #include<map> #include<queue> #define INF 0x3f3f3f3f; #define ll long long ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);} using namespace std; const int manx=1e5+10; int main() { int n,m,a[110],ans=0,cnt1=0,cnt2=0,b[110],c=0,sum=0; cin>>n>>m; for(int i=0; i<n; i++) cin>>a[i]; for(int i=0; i<n; i++) { if(a[i]%2) cnt1++; else cnt2++; if(cnt1==cnt2&&i+1<n) b[c++]=abs(a[i]-a[i+1]); } sort(b,b+c); for(int i=0; i<c; i++) { sum+=b[i]; if(sum<=m) ans++; else break; } cout<<ans; return 0; }
Cutting Codeforces Round #493 (Div. 2)