#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 300000 + 10;
const ll N = 4e10 + 2;
map<ll,int> fen;
int get(ll x){
int ret = 0;
x ++;
if (x < 0)
x = 0;
for (; x; x -= x & -x)
if (fen.count(x))
ret += fen[x];
return ret;
}
void add(ll x){
for (x ++; x <= N; x += x & -x)
fen[x] ++;
}
vector<pair<ll,ll> > get(vector<pair<ll,ll> > &a, bool wh){
vector<pair<ll,ll>> c;
int n = a.size();
for (int mask = 1; mask < (1 << n); mask++){
ll last = -1, first = -1;
bool flag = 1;
ll sum = 0;
for (int i = 0; i < n; i++){
if (!(mask & (1 << i)))
continue;
if (last > a[i].first){
flag = 0;
break;
}
if (first == -1)
first = a[i].first;
last = a[i].first;
sum += a[i].second;
}
if (flag == 0)
continue;
if (wh == 0)
c.push_back({last, sum});
else
c.push_back({first, sum});
}
if (wh == 0)
c.push_back({1, 0});
else
c.push_back({1000*1000*1000, 0});
return c;
}
int main(){
ios_base::sync_with_stdio(false);
int n;
ll k;
cin >> n >> k;
vector<pair<ll,ll> > a, b;
for (int i = 0; i < n; i++){
ll h, g;
cin >> h >> g;
if (i < n / 2)
a.push_back({h, g});
else
b.push_back({h, g});
}
vector<pair<ll,ll>> c = get(a, 0);
vector<pair<ll,ll>> d = get(b, 1);
sort(c.begin(), c.end());
sort(d.begin(), d.end());
int ptr = 0;
n = c.size();
int m = d.size();
ll answer = 0;
for (int i = 0; i < d.size(); i++){
while (ptr < n and c[ptr].first <= d[i].first)
add(c[ptr ++].second);
answer += ptr - get(k - d[i].second - 1);
}
cout << answer << endl;
}
Compilation message
san.cpp: In function 'int main()':
san.cpp:82:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < d.size(); i++){
~~^~~~~~~~~~
san.cpp:79:6: warning: unused variable 'm' [-Wunused-variable]
int m = d.size();
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
20848 KB |
Output is correct |
2 |
Correct |
10 ms |
1016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
17616 KB |
Output is correct |
2 |
Correct |
70 ms |
10992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
510 ms |
65540 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |