Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define nl '\n'
- using namespace std;
- int main(){
- long int t; cin>>t;
- while(t--){
- long int n; cin>>n;
- long int arr[n];
- long int newzom=0, ans=0;
- for(long int i=0; i<n; i++){
- cin>>arr[i];
- }
- for(long int i=0; i<n; i++){
- if(arr[i]%3==0 && arr[i]%5==0){
- newzom+=arr[i];
- ans+=arr[i];
- } else {
- if(arr[i]>=newzom){
- ans+=newzom;
- newzom=0;
- } else {
- ans+=arr[i];
- newzom-=arr[i];
- }
- }
- }
- cout<<ans<<nl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement