11264 - Coin Collector Solution
Problem Link: here
solution: Implementation.
#include<bits/stdc++.h>
using namespace std;
#define MX 1007
#define LL long long
int main()
{
int t,cs = 0;
scanf("%d",&t);
while(t--)
{
int n;
LL total = 0, cnt = 1;
scanf("%d",&n);
vector<LL>input;
vector<LL> p;
total = 0;
for(int i = 0; i < n; i++)
{
int x;
cin >> x;
p.push_back(x);
}
total = p[0];
for (int i=1; i<n-1; i++)
{
if (total+p[i] >= p[i+1]) continue;
else
{
total+=p[i];
cnt++;
}
}
if (total<p[n-1]) cnt++;
cout << cnt << endl;
}
return 0;
}
using namespace std;
#define MX 1007
#define LL long long
int main()
{
int t,cs = 0;
scanf("%d",&t);
while(t--)
{
int n;
LL total = 0, cnt = 1;
scanf("%d",&n);
vector<LL>input;
vector<LL> p;
total = 0;
for(int i = 0; i < n; i++)
{
int x;
cin >> x;
p.push_back(x);
}
total = p[0];
for (int i=1; i<n-1; i++)
{
if (total+p[i] >= p[i+1]) continue;
else
{
total+=p[i];
cnt++;
}
}
if (total<p[n-1]) cnt++;
cout << cnt << endl;
}
return 0;
}

No comments