Codeforces Round 918 (Div. 4) 1915E. Romantic Glasses Solution
Problem Link : https://codeforces.com/contest/1915/problem/E
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n ;
- cin >> n ;
- int a[n+2] ;
- for(int i = 1 ; i <= n ; i++){
- cin >> a[i] ;
- }
- map<long long ,long long >mp ;
- long long sum = 0 ;
- mp[sum] = 1 ;
- bool ok = false ;
- for ( int i = 1 ; i <= n ; i++ ){
- if (i%2){
- sum +=a[i] ;
- }
- else{
- sum -=a[i] ;
- }
- if (mp[sum]){
- ok = true ;
- break ;
- }
- mp[sum] = 1 ;
- }
- if (ok) cout <<"YES\n";
- else cout <<"NO\n";
- }
- return 0 ;
- }
No comments