#include #include using namespace std; int main() { unsigned int tmpA; unsigned long tmpB, tmpC; unsigned int n; unsigned int m; unsigned long k; unsigned long start, terminate; map maxCorridor; unsigned long sumCorridor=0; cin>>n>>m>>k>>start>>terminate; if(start> tmpA >> tmpB >> tmpC; if (maxCorridor.count(tmpA) == 0 || maxCorridor[tmpA] < tmpC - tmpB) maxCorridor[tmpA] = tmpC - tmpB; } for (unsigned int i = 1; i < n; ++i) { if (maxCorridor.count(i) == 0) { cout << "-1" << endl; return 1; } sumCorridor += maxCorridor[i]; } cout << terminate - start - sumCorridor << endl; } else { for (int i = 0; i < m; i++) { cin >> tmpA >> tmpB >> tmpC; if (maxCorridor.count(tmpA) == 0 || maxCorridor[tmpA] < tmpB - tmpC) maxCorridor[tmpA] = tmpB - tmpC; } for (unsigned int i = 1; i < n; ++i) { if (maxCorridor.count(i) == 1) { cout << "-1" << endl; return 1; } sumCorridor += maxCorridor[i]; } cout << start - terminate - sumCorridor << endl; } return 0; }