1320A - Journey Planning - CodeForces Solution


data structures dp greedy math sortings *1400

Please click on ads to support us..

C++ Code:

#ifndef __KUTORI__
#define __KUTORI__

#include <map>
#include <iostream>
using namespace std;
typedef long long int64;

const int N = 2e5;
int b[N+5];

int main() {
    ios::sync_with_stdio(0); cin.tie(nullptr);
    int n, i; cin >> n;
    for (i = 1; i <= n; i++) cin >> b[i];
    // solve
    int64 ans = -1e9;
    map<int, int64> ATshayu;
    for (i = 1; i <= n; i++) {
        int v = b[i] - i;
        if (ATshayu.count(v) == 0) ATshayu[v] = b[i];
        else ATshayu[v] += b[i];
        ans = max(ans, ATshayu[v]);
    }
    cout << ans << "\n";
    return 0;
}

#endif


Comments

Submit
0 Comments
More Questions

1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected
282A - Bit++
69A - Young Physicist
1651A - Playoff
734A - Anton and Danik
1300B - Assigning to Classes
1647A - Madoka and Math Dad
710A - King Moves
1131A - Sea Battle
118A - String Task
236A - Boy or Girl
271A - Beautiful Year
520B - Two Buttons
231A - Team