Skip to content

Instantly share code, notes, and snippets.

@ravijain056
Created August 14, 2015 22:31
Show Gist options
  • Save ravijain056/bff2cbcae0a2f28d7fe4 to your computer and use it in GitHub Desktop.
Save ravijain056/bff2cbcae0a2f28d7fe4 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while(t--) {
long int cave_size, tractor_size;
cin >> cave_size >> tractor_size;
int cave[cave_size][cave_size];
long int col, row;
for(col = 0; col < cave_size; col++) {
long int I, H;
cin >> I >> H;
for(row = 0; row < cave_size; row++) {
if(row < I || row > H) {
cave[col][row] = 1;
} else {
cave[col][row] = 0;
}
}
}
for(row = 0;row < cave_size;row++) {
for(col = 1; col < cave_size; col++) {
cave[0][row] += cave[col][row];
}
}
long long int energy, min_energy = cave_size * tractor_size;
for(row = 0; row <= cave_size - tractor_size; row++) {
energy = 0;
for(col = 0; col < tractor_size; col++) {
energy += cave[0][row + col];
}
if(energy < min_energy) {
min_energy = energy;
}
}
cout << min_energy << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment