#include <cstdio> #include <cassert> #include <algorithm> int main() { int m, n; scanf("%d %d", &m, &n); long long w, h; scanf("%lld %lld", &w, &h); long long exponats_x[m], exponats_y[m], exponats_price[m]; long long sentinels_x[n], sentinels_y[n], sentinels_cost[n]; for(int i=0;i<m;i++) { scanf("%lld %lld %lld", &exponats_x[i], &exponats_y[i], &exponats_price[i]); } for(int i=0;i<n;i++) { scanf("%lld %lld %lld", &sentinels_x[i], &sentinels_y[i], &sentinels_cost[i]); } long long best = 0; for(int comb=0;comb< 1<<n; comb++) { int summary = 0; int tcomb = comb; for(int j=0;j<n;j++) { if(!(tcomb&1)) summary -= sentinels_cost[j]; tcomb>>=1; } for(int i=0;i<m;i++)//exponats { bool stealable = true; int tcomb = comb; for(int j=0;j<n;j++)//sentinels { if(tcomb&1) { if(exponats_y[i]<=sentinels_y[j] && abs(exponats_x[i]-sentinels_x[j])*h<=w*abs(exponats_y[i]-sentinels_y[j])) stealable = false; } tcomb >>= 1; } if(stealable) summary += exponats_price[i]; } if(summary>best) best = summary; } printf("%lld\n", best); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <cstdio> #include <cassert> #include <algorithm> int main() { int m, n; scanf("%d %d", &m, &n); long long w, h; scanf("%lld %lld", &w, &h); long long exponats_x[m], exponats_y[m], exponats_price[m]; long long sentinels_x[n], sentinels_y[n], sentinels_cost[n]; for(int i=0;i<m;i++) { scanf("%lld %lld %lld", &exponats_x[i], &exponats_y[i], &exponats_price[i]); } for(int i=0;i<n;i++) { scanf("%lld %lld %lld", &sentinels_x[i], &sentinels_y[i], &sentinels_cost[i]); } long long best = 0; for(int comb=0;comb< 1<<n; comb++) { int summary = 0; int tcomb = comb; for(int j=0;j<n;j++) { if(!(tcomb&1)) summary -= sentinels_cost[j]; tcomb>>=1; } for(int i=0;i<m;i++)//exponats { bool stealable = true; int tcomb = comb; for(int j=0;j<n;j++)//sentinels { if(tcomb&1) { if(exponats_y[i]<=sentinels_y[j] && abs(exponats_x[i]-sentinels_x[j])*h<=w*abs(exponats_y[i]-sentinels_y[j])) stealable = false; } tcomb >>= 1; } if(stealable) summary += exponats_price[i]; } if(summary>best) best = summary; } printf("%lld\n", best); } |