This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define DEBUG
#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif
ll n,p,m,ans;
ll arr[45],cost[45];
vector<ll> poss[45];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> p;
for(ll i=1;i<=n;i++){
cin >> arr[i] >> cost[i];
}
m = n/2;
for(ll i=1;i<=m;i++){
poss[i].push_back(cost[i]);
for(ll j=1;j<i;j++){
if(arr[i]>=arr[j]){
for(ll k:poss[j]){
poss[i].push_back(k+cost[i]);
}
}
}
}
for(ll i=m+1;i<=n;i++){
poss[i].push_back(cost[i]);
for(ll j=m+1;j<i;j++){
if(arr[i]>=arr[j]){
for(ll k:poss[j]){
poss[i].push_back(k+cost[i]);
}
}
}
}
for(ll i=m+1;i<=n;i++){
deque<ll> dq;
for(ll j=1;j<=m;j++){
if(arr[i]>=arr[j]){
for(ll k:poss[j]){
dq.push_back(k);
}
}
}
sort(dq.begin(),dq.end());
sort(poss[i].begin(),poss[i].end(),greater<ll>());
for(ll j:poss[i]){
while(dq.size()>0 and dq.front()+j<p){
dq.pop_front();
}
ll siz = dq.size();
ans += siz;
}
}
for(ll i=1;i<=n;i++){
for(ll j:poss[i]){
if(j>=p){
ans++;
}
}
}
cout << ans << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |