Skip to content

Commit ce02722

Browse files
committed
Update
1 parent 3967678 commit ce02722

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

Important.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
12-> upper_bound return the iterator of the elemen with is greatere then it;
1313
13->int set/map we use upper and lower bound diff as set.upper_bound(3); in vector upper_bound(v.begin(),v.end(),target);because working in vector is BS and in set its tree
1414
14->int sum=accumulate(v.begin(),v.end(),0(initial sum value)); to get sum of vector;
15-
//7986952804
15+
15-> transform(s.begin(), s.end(), s.begin(), ::tolower); to make string lower ;
1616
sweepline adhoc
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
typedef long long ll;
4+
#define MOD 1000000007
5+
#define pb push_back
6+
#define ppb pop_back
7+
#define ff first
8+
#define ss second
9+
#define PI 3.141592653589793238462
10+
#define set_bits __builtin_popcountll
11+
#define all(x) (x).begin(), (x).end()
12+
#define debug(x) cerr<<x<<" ";
13+
14+
15+
int main()
16+
{
17+
ios_base::sync_with_stdio(false);
18+
cin.tie(NULL);
19+
ll n;
20+
cin>>n;
21+
22+
vector<ll>prefix(n+1);
23+
vector<ll>suffix(n+1);
24+
vector<ll>v(n+1,0);
25+
//taking input
26+
for(ll i=1;i<=n;i++)
27+
{
28+
cin>>v[i];
29+
}
30+
//making prefix array
31+
for(ll i=1;i<=n;i++)
32+
{
33+
prefix[i]=prefix[i-1]+v[i];
34+
}
35+
//making suffix array
36+
for(ll i=n;i>=1;i--)
37+
{
38+
if(i==n)suffix[i]=v[i];
39+
else suffix[i]=suffix[i+1]+v[i];
40+
}
41+
ll mini=INT_MAX;
42+
for(ll i=1;i<n;i++)
43+
{
44+
ll temp=abs(suffix[i+1]-prefix[i]);
45+
mini=min(mini,temp);
46+
}
47+
cout<<mini<<endl;
48+
}
49+
50+

0 commit comments

Comments
 (0)