Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Zhandos Kapezov
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <vector>
- #include <utility>
- #include <algorithm>
- #include <cstdio>
- #include <cstdlib>
- #include <fstream>
- #include <string>
- #include <string.h>
- #include <sstream>
- #include <map>
- #include <set>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <limits>
- #include <list>
- #include <functional>
- #include <bitset>
- #include <numeric>
- #include <iomanip>
- #include <ctime>
- #include <ctype.h>
- using namespace std;
- typedef long long ll;
- #define F first
- #define S second
- #define pb push_back
- #define mp make_pair
- #define sz size()
- #define sqr(x) ((x)*(x))
- #define INF numeric_limits<int>::max()
- int bit(int x, int i) {
- return (x>>i)&1;
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("input.txt","rt",stdin);
- freopen("output.txt","wt",stdout);
- #endif
- cin>>x>>n; res=-1; pp=1;
- for (int i=0; i<n; i++) pp*=x;
- for (int i=0; i<n; i++) cin>>a[i];
- for (int p=0; p<pp; p++) {
- cur=p; now=0; j=0; nn=0;
- while (cur) {
- now+=a[j]*(cur%3);
- nn+=cur%3;
- cur/=3; j++;
- }
- if (now>x) res=0;
- if (now==x) {
- if (!res) res=nn; else
- res=min(res, nn);
- }
- }
- cout<<res;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement