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<bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int unsigned long long
#define a first
#define b second
#define pii pair<int, int>
using namespace std;
const int sz = 2e5 + 5;
const int inf = 1e9 + 7;
int n, ans;
pii c[sz];
bool check(int d){
int cnt(0);
for(register int i = 0; i <= 20; ++i){
if(d & (1LL << i)) ++cnt;
}
return cnt >= 2;
}
signed main(){
SPEED;
cin >> n;
for(register int i = 1; i <= n; ++i){
cin >> c[i].a >> c[i].b;
}
for(register int mask = 1; mask < (1LL << n); ++mask){
int s(0), mxa(0), mna{inf};
// if(!check(mask)) continue;
for(register int i = 1; i <= n; ++i){
if(mask & (1LL << (i-1))){
s += c[i].b;
mxa = max(mxa, c[i].a), mna = min(mna, c[i].a);
}
}
int dif = mxa - mna;
if(dif > s) continue;
ans = max(ans, s - dif);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
art.cpp: In function 'bool check(long long unsigned int)':
art.cpp:20:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
20 | for(register int i = 0; i <= 20; ++i){
| ^
art.cpp: In function 'int main()':
art.cpp:30:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
30 | for(register int i = 1; i <= n; ++i){
| ^
art.cpp:33:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
33 | for(register int mask = 1; mask < (1LL << n); ++mask){
| ^~~~
art.cpp:33:37: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
33 | for(register int mask = 1; mask < (1LL << n); ++mask){
| ~~~~~^~~~~~~~~~~~
art.cpp:38:26: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
38 | for(register int i = 1; i <= n; ++i){
| ^
# | 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... |