이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
dq.push_back(0);
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();
}
ans += dq.size();
}
}
for(ll i=1;i<=m;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... |