#include <iostream>
#include <vector>
using namespace std;
int main()
{
long long a,b,c,d;
cin>>a>>b>>c;
vector<long long>w(c);
for(int i=0;i<c;i++){
cin>>d;
w[i]=d;
}
int e=a*b;
int j=w.size()-1;
int licznik=0, f=0;
while(e>w[0]){
if(e>w[j]*w[j]){
f=e/(w[j]*w[j]);
e-=f*(w[j]*w[j]);
licznik+=f;
}
j--;
}
if(e>0) cout<<-1;
else cout<<licznik;
return 0;
}
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 | #include <iostream> #include <vector> using namespace std; int main() { long long a,b,c,d; cin>>a>>b>>c; vector<long long>w(c); for(int i=0;i<c;i++){ cin>>d; w[i]=d; } int e=a*b; int j=w.size()-1; int licznik=0, f=0; while(e>w[0]){ if(e>w[j]*w[j]){ f=e/(w[j]*w[j]); e-=f*(w[j]*w[j]); licznik+=f; } j--; } if(e>0) cout<<-1; else cout<<licznik; return 0; } |
English