diff --git a/.cph/.arrayrecovery.cpp_7b3b9871d14eed2f4ce9e9619c6c4e79.prob b/.cph/.arrayrecovery.cpp_7b3b9871d14eed2f4ce9e9619c6c4e79.prob new file mode 100644 index 0000000..f8f73be --- /dev/null +++ b/.cph/.arrayrecovery.cpp_7b3b9871d14eed2f4ce9e9619c6c4e79.prob @@ -0,0 +1 @@ +{"name":"Local: arrayrecovery","url":"c:\\Users\\CC\\Desktop\\git-anurag\\git-akpro\\leetcode-solutions-1\\arrayrecovery.cpp","tests":[{"id":1666365548858,"input":"","output":""}],"interactive":false,"memoryLimit":1024,"timeLimit":3000,"srcPath":"c:\\Users\\CC\\Desktop\\git-anurag\\git-akpro\\leetcode-solutions-1\\arrayrecovery.cpp","group":"local","local":true} \ No newline at end of file diff --git a/arrayrecovery.cpp b/arrayrecovery.cpp new file mode 100644 index 0000000..d0649ae --- /dev/null +++ b/arrayrecovery.cpp @@ -0,0 +1,66 @@ +// shree ganeshay namah +#include +using namespace std; +#define ll long long +#define pi (3.141592653589) +#define mod 1000000007 +#define ll long long +#define float double +#define pb push_back +#define mp make_pair +#define ff first +#define ss second +#define all(c) c.begin(), c.end() +#define min3(a, b, c) min(c, min(a, b)) +#define min4(a, b, c, d) min(d, min(c, min(a, b))) +#define rrep(i, n) for (int i = n - 1; i >= 0; i--) +#define rep(i, n) for (int i = 0; i < n; i++) +#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); + +int main() +{ + int t; + cin >> t; + while (t--) + { + int n; + cin >> n; + int c = 0; + vector a(n); + vector b(n); + int flag = 0; + for (int i = 0; i < n; i++) + { + cin >> a[i]; + } + b[0] = a[0]; + for (int i = 1; i < n; i++) + { + if(a[i]==0){ + b[i] = b[i-1] + a[i]; + continue; + } + if (b[i-1] - a[i] >= 0) + { + flag = 1; + break; + } + else{ + b[i] = a[i] + b[i - 1]; + } + } + for (int i = 0; i < n; i++) + { + if (flag == 0) + { + cout << b[i] << " "; + } + else{ + cout << "-1"; + break; + } + } + cout<