#include <bits/stdc++.h> //#include <emmintrin.h> using namespace std; #define FORE(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,a) FOR(i,0,a) #define ZERO(m) memset(m,0,sizeof(m)) #define ALL(x) x.begin(),x.end() #define PB push_back #define S size() #define LL long long #define ULL unsigned long long #define LD long double #define MP make_pair #define X first #define Y second #define VC vector #define PII pair <int, int> #define VI VC < int > #define VVI VC < VI > #define VD VC < double > #define VVD VC < VD > #define VS VC < string > #define DB(a) cerr << #a << ": " << (a) << endl; template<class T> void print(VC < T > v) {cerr << "[";if (v.S) cerr << v[0];FOR(i, 1, v.S) cerr << ", " << v[i];cerr << "]\n";} template<class T> string i2s(T x) {ostringstream o; o << x; return o.str(); } VS splt(string s, char c = ' ') {VS all; int p = 0, np; while (np = s.find(c, p), np >= 0) {if (np != p) all.PB(s.substr(p, np - p)); p = np + 1;} if (p < s.S) all.PB(s.substr(p)); return all;} const int MAX_N = 200100; int N, M; LL W, H; int GX[MAX_N]; int GY[MAX_N]; int GV[MAX_N]; int EX[MAX_N]; int EY[MAX_N]; int EV[MAX_N]; LL TX[MAX_N*2]; LL TY[MAX_N*2]; pair < LL, int > VP[MAX_N*2]; int OX[MAX_N*2]; int OY[MAX_N*2]; int OV[MAX_N*2]; LL DP[MAX_N*2]; int main() { cin >> N >> M >> W >> H; REP(i, N) scanf("%d%d%d", &EX[i], &EY[i], &EV[i]); REP(i, M) scanf("%d%d%d", &GX[i], &GY[i], &GV[i]); REP(i, N) TX[i] = (EX[i]*H-EY[i]*W)*2+1, TY[i] = -(EX[i]*H+EY[i]*W)*2+1; REP(i, M) TX[N+i] = (GX[i]*H-GY[i]*W)*2, TY[N+i] = -(GX[i]*H+GY[i]*W)*2; // REP(i, N) cout << TX[i] << ' ' << TY[i] << ' ' << EV[i] << endl; cout << endl; // REP(i, M) cout << TX[i+N] << ' ' << TY[i+N] << ' ' << GV[i] << endl; cout << endl; REP(i, N+M) VP[i] = MP(TX[i], i); sort(VP, VP+N+M); REP(i, N+M) OX[i] = VP[i].Y; REP(i, N+M) VP[i] = MP(TY[i], i); sort(VP, VP+N+M); REP(i, N+M) TY[VP[i].Y] = i; REP(i, N+M) OY[i] = TY[OX[i]]; REP(i, N+M) OV[i] = OX[i] < N ? EV[OX[i]] : -GV[OX[i]-N]; // REP(i, N+M) cout << OY[i] << ' ' << OV[i] << endl; int T = N+M; REP(i, T) { DP[T-1] = DP[T-1] + OV[i]; for (int j = T - 2; j >= OY[i]; j--) DP[j] = max(DP[j+1], DP[j]+OV[i]); for (int j = OY[i] - 1; j >= 0; j--) DP[j] = max(DP[j+1], DP[j]); } cout << DP[0] << endl; return 0; }
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #include <bits/stdc++.h> //#include <emmintrin.h> using namespace std; #define FORE(it,c) for(__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,a) FOR(i,0,a) #define ZERO(m) memset(m,0,sizeof(m)) #define ALL(x) x.begin(),x.end() #define PB push_back #define S size() #define LL long long #define ULL unsigned long long #define LD long double #define MP make_pair #define X first #define Y second #define VC vector #define PII pair <int, int> #define VI VC < int > #define VVI VC < VI > #define VD VC < double > #define VVD VC < VD > #define VS VC < string > #define DB(a) cerr << #a << ": " << (a) << endl; template<class T> void print(VC < T > v) {cerr << "[";if (v.S) cerr << v[0];FOR(i, 1, v.S) cerr << ", " << v[i];cerr << "]\n";} template<class T> string i2s(T x) {ostringstream o; o << x; return o.str(); } VS splt(string s, char c = ' ') {VS all; int p = 0, np; while (np = s.find(c, p), np >= 0) {if (np != p) all.PB(s.substr(p, np - p)); p = np + 1;} if (p < s.S) all.PB(s.substr(p)); return all;} const int MAX_N = 200100; int N, M; LL W, H; int GX[MAX_N]; int GY[MAX_N]; int GV[MAX_N]; int EX[MAX_N]; int EY[MAX_N]; int EV[MAX_N]; LL TX[MAX_N*2]; LL TY[MAX_N*2]; pair < LL, int > VP[MAX_N*2]; int OX[MAX_N*2]; int OY[MAX_N*2]; int OV[MAX_N*2]; LL DP[MAX_N*2]; int main() { cin >> N >> M >> W >> H; REP(i, N) scanf("%d%d%d", &EX[i], &EY[i], &EV[i]); REP(i, M) scanf("%d%d%d", &GX[i], &GY[i], &GV[i]); REP(i, N) TX[i] = (EX[i]*H-EY[i]*W)*2+1, TY[i] = -(EX[i]*H+EY[i]*W)*2+1; REP(i, M) TX[N+i] = (GX[i]*H-GY[i]*W)*2, TY[N+i] = -(GX[i]*H+GY[i]*W)*2; // REP(i, N) cout << TX[i] << ' ' << TY[i] << ' ' << EV[i] << endl; cout << endl; // REP(i, M) cout << TX[i+N] << ' ' << TY[i+N] << ' ' << GV[i] << endl; cout << endl; REP(i, N+M) VP[i] = MP(TX[i], i); sort(VP, VP+N+M); REP(i, N+M) OX[i] = VP[i].Y; REP(i, N+M) VP[i] = MP(TY[i], i); sort(VP, VP+N+M); REP(i, N+M) TY[VP[i].Y] = i; REP(i, N+M) OY[i] = TY[OX[i]]; REP(i, N+M) OV[i] = OX[i] < N ? EV[OX[i]] : -GV[OX[i]-N]; // REP(i, N+M) cout << OY[i] << ' ' << OV[i] << endl; int T = N+M; REP(i, T) { DP[T-1] = DP[T-1] + OV[i]; for (int j = T - 2; j >= OY[i]; j--) DP[j] = max(DP[j+1], DP[j]+OV[i]); for (int j = OY[i] - 1; j >= 0; j--) DP[j] = max(DP[j+1], DP[j]); } cout << DP[0] << endl; return 0; } |