Varianta 29 / Subiectul 3 / Problema 4 |
#include<fstream.h> void main() { int n,m,a[100],b[100],i,j,s,gata; ifstream f("bac.in"); f>>n>>m; for(i=1;i<=n;i++) f>>a[i]; for(i=1;i<=m;i++) f>>b[i]; i=1;j=1;s=0;gata=0; while(i<=n && j<=m && !gata) { while(s<b[j] && i<=n) { s=s+a[i]; i++;} if(s==b[j]) { s=0; j++;} else gata=1; } if(gata || i<=n || j<=m) cout<<"nu"; else cout<<"da"; } |