Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int s, k, n, sum, x[25], a[25][25];
- bool ok;
- void Solve(int t) {
- for(int i=1;i<=n;i++)
- if(a[i][t]>=x[t-1]) {
- if(a[i][t]<=(s-sum)/(k-t+1)) {
- x[t]=a[i][t];
- sum+=x[t];
- if(t==k) {
- if(sum==s) ok=true;
- } else Solve(t+1);
- sum-=x[t];
- }
- if(ok) return;
- }
- }
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("trangtri.inp", "r", stdin);
- #endif // ONLINE_JUDGE
- scanf("%d%d%d", &s, &k, &n);
- for(int i=1;i<=n;i++)
- for (int j=1;j<=k;j++) scanf("%d", &a[i][j]);
- ok=false;
- Solve(1);
- if(ok) {
- printf("YES\n");
- for (int i=1;i<=k;i++) printf("%d ",x[i]);
- } else printf("NO");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment