From ca77c08d1d2a3eaba3d036c3f671a9b6d53924ad Mon Sep 17 00:00:00 2001 From: ShazidMahsrafi Date: Wed, 13 Dec 2023 02:54:32 +0600 Subject: [PATCH] added 1118B --- 1118B Tanya and Candies/1118B.cpp | 100 ++++++++++++++++++++++++++++++ Readme.md | 1 + 2 files changed, 101 insertions(+) create mode 100644 1118B Tanya and Candies/1118B.cpp diff --git a/1118B Tanya and Candies/1118B.cpp b/1118B Tanya and Candies/1118B.cpp new file mode 100644 index 0000000..8f325f7 --- /dev/null +++ b/1118B Tanya and Candies/1118B.cpp @@ -0,0 +1,100 @@ +#include +using namespace std; + +// Short forms +#define int long long +#define ll long long +#define endl '\n' +#define ff first +#define ss second +#define pb push_back +#define all(x) x.begin(), x.end() +#define sz(x) (int)(x).size() + +// Outputs +#define yes cout<<"YES"< void _print(pair p); +template void _print(vector v);template void _print(set v); +template void _print(map v);template void _print(multiset v); +template void _print(pair p) {cerr << "{"; _print(p.first); cerr << ","; _print(p.second); cerr << "}";} +template void _print(vector v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(set v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(multiset v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";} +template void _print(map v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +void solve() +{ + int n; + cin >> n; + int suf_even=0, suf_odd=0, pre_even=0, pre_odd=0; + vectorv(n+1); + for(int i=1;i<=n;i++) + { + cin>>v[i]; + if(i&1) + suf_odd+=v[i]; + else + suf_even+=v[i]; + } + int ct=0; + dbg(suf_even); + dbg(suf_odd); + for(int i=1; i<=n; ++i) + { + if(i&1) + suf_odd-=v[i]; + else + suf_even-=v[i]; + if(suf_even+pre_odd==suf_odd+pre_even) + { + ct++; + } + if(i&1) + pre_odd+=v[i]; + else + pre_even+=v[i]; + } + cout<> TC; + while (TC--) + solve(); +} \ No newline at end of file diff --git a/Readme.md b/Readme.md index 1efb10f..e95e4a1 100644 --- a/Readme.md +++ b/Readme.md @@ -78,6 +78,7 @@ Feel free to check these codes out. | 854A | Fraction | Question](https://codeforces.com/problemset/problem/854/A) | [Solution] | 855A | Tom Riddle's Diary | [Question](https://codeforces.com/problemset/problem/855/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/blob/master/855A%20Tom%20Riddle's%20Diary/855A.cpp) | 977A | Wrong Substraction | [Question](https://codeforces.com/problemset/problem/977/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/blob/master/977A%20Wrong%20Substraction/977A.cpp) +| 1118B | Tanya and Candies | [Question](https://codeforces.com/contest/1118/problem/B) | [Solution] | 1068A | Birthday | [Question](https://codeforces.com/contest/1068/problem/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/blob/master/1068A%20Birthday/1068A.cpp) | 1144C | Two Shuffled Sequences | [Question](https://codeforces.com/problemset/problem/1144/C) | [Solution] | 1196A | Three Piles of Candies | [Question](https://codeforces.com/problemset/problem/1196/A) | [Solution](https://github.com/ShazidMashrafi/Codeforces-Solutions/blob/master/1196A%20Three%20Piles%20of%20Candies/1196A.cpp)