codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
//Flatten //cho nhieu cot co do cao khac nhau, chuyen lan luot tung o tu cot cao nhat den cot thap nhat. sau dump lan chuyen, xuat ra hieu cao nhat - thap nhat #include <iostream> #include <conio.h> using namespace std; int main() { int dump; int boxes[100]; freopen("Testcase.txt", "r", stdin); for(int testcase = 1; testcase <= 10; testcase++) { int i, d; cin >> dump; for(i = 0; i < 100; i++) cin >> boxes[i]; while(dump >= 0) { int max = 1, min = 100; int posMax = 0, posMin = 0; for(i = 0; i < 100; i++) { if(max < boxes[i]) { max = boxes[i]; posMax = i; } if(min > boxes[i]) { min = boxes[i]; posMin = i; } } if(dump == 0) { d = max - min; } else { boxes[posMax]--; boxes[posMin]++; } dump--; } cout << "#" << testcase << " " << d << endl; } getch(); return 0; }
Private
[
?
]
Run code
Submit