-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathempaquetar.cpp
52 lines (48 loc) · 1.06 KB
/
empaquetar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
using namespace std;
struct hoja{
int r;
hoja (int x1) : r(x1) {}
};
bool metodo(hoja a,hoja b){
return a.r < b.r;
}
void calcular(const vector<hoja> a,const int S){
vector<hoja>::const_iterator it = a.begin();
int aux=0,paquetes=0;
for(;it<a.end();it++){
cout << aux << ' ' << (*it).r << endl;
if( (*it).r >= S ){
paquetes++;
} else if( aux+(*it).r == S ){
aux=0;
paquetes++;
} else if( aux+(*it).r > S ){
aux=0;
paquetes++;
} else {
aux+=(*it).r;
}
}
if(aux>0) paquetes++;
ofstream fout("out.txt");
fout << paquetes;
}
int main(){
vector<hoja> lista;
ifstream fin("in.txt");
int z,x,c,S,r;
fin >> S >> z;
fin >> z >> x >> c;
while(!fin.eof()){
r = z+x+c;
hoja nuevo(r);
lista.push_back(nuevo);
fin >> z >> x >> c;
}
sort(lista.begin(),lista.end(),metodo);
calcular(lista,S);
}