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 | #include <iostream> #include <cstdlib> using namespace std; int tab[201]; int main() { int n,w,a, kajaki=0, min=1000; cin>>w>>n; for(int i=0; i<n; i++) { cin>>a; if(a<=min)min=a; tab[a]++; } a=w; while(tab[a]) { kajaki++; tab[a]--;} while(min!=a) { if(tab[min]==0){min++; continue;} if(tab[a]==0){a--; continue;} if(a+min<=w)while(tab[a]!=0 && tab[min]!=0){tab[a]--; tab[min]--; kajaki++;} else while(tab[a]!=0){kajaki++; tab[a]--;} } while(tab[min]!=0){kajaki++; tab[min]--;} cout<<kajaki; return 0; } |
-
upload with new input
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
100 5 100 50 50 50 50
5
-
result: Success time: 0.01s memory: 2728 kB returned value: 0
10 1 10
1
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
100 10 30 30 31 100 100 100 5 5 5 5
7
-
result: Success time: 0.01s memory: 2728 kB returned value: 0
100 9 90 20 20 30 50 60 70 80 90
6
-
result: Success time: 0.01s memory: 2728 kB returned value: 0
100 6 100 20 30 30 22 31
4
-
result: Success time: 0.02s memory: 2728 kB returned value: 0
100 3 10 20 30
2
-
result: Runtime error time: 0.01s memory: 2724 kB signal: 11 (SIGSEGV)



