#include #include #include using namespace std; int calculateMin( int * startP, int * endP, int height ) { int min = INT_MAX; for ( int i = 0; i < height; i++ ) { for ( int j = i; j < height; j++ ) { int val = abs(endP[j] - startP[i]) + j - i; if ( val < min ) min = val; } } return min; } int main() { int cases; cin >> cases; int height = 0; for ( int i = 0; i < cases; i++ ) { cin >> height; int * startP = new int[height]; int * endP = new int[height]; for ( int j = 0; j < height; j++ ) { cin >> startP[j] >> endP[j]; } int min = calculateMin(startP, endP, height); cout << "K prechodu reky je treba " << min << " pontonu." << endl; delete [] startP; delete [] endP; } return 0; }