#include #include int absz( int x ) { return x > 0 ? x : -x; } int main( void ) { int N = 1, M = 1; std::cin >> N >> M; std::vector L( N ); for (int i = 0;i < N;i++) { std::cin >> L[i]; } int F = 0, B = 0, W = 0; int sum = 0; for (int i = 0; i < M; i++) { std::cin >> F >> B >> W; int nearest = 2000000000; for (int j = 0; j < N; j++) { int d = absz( F - L[j] ); if (d < nearest) nearest = d; } if (nearest < 1) { sum += W; } else if (nearest < W - B) { sum += W - nearest; } else { sum += B; } } std::cout << sum; return 0; }