This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the name of god
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#define Sort(x) sort(all(x))
#define debug(x) cerr << #x << " : " << x << "\n"
#define use_file freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef string str;
const ll maxn = 1e5 + 6, inf = 1e18, mod = 1e9 + 7, mod2 = 1e9 + 9;
ll n, l, a[maxn], b[maxn];
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> l;
for(ll i = 0; i < n; i ++)cin >> a[i];
for(ll i = 0; i < n; i ++)b[i] = i;
ll ans = 0;
while(true){
ll dif = 0;
for(ll i = 1; i < n; i ++)dif += abs(a[b[i]] - a[b[i - 1]]);
if(dif <= l)ans ++;
if(next_permutation(b, b + n))ans = ans;
else break;
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |