abbyy cup a

July 24, 2013
CodeForces

link: http://codeforces.com/contest/331/problem/A2


/*
ID: zypz4571
LANG: C++
TASK: abby_a.cpp
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <deque>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <functional>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#include <ctime>
#include <iterator>
const int INF = 0x3f3f3f3f;
const int dir[8][2] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}};
using namespace std;
long long int a[300009], sum[300009];
map<int, int> coll;
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    int n; cin>>n;
    sum[0] = 0;
    for (int i = 1; i<= n; ++i) {
        cin>>a[i];
        sum[i] = sum[i-1] + (a[i]>=0?a[i]:0);
    }
    int L, R;
    long long ans=-(long long)2e18;
    for (int i = n; i >= 1; --i) {
        if (coll.count(a[i]) > 0) {
            int pos = coll[a[i]];
            long long tmp = a[i]*2+sum[pos-1]-sum[i];
            if (tmp > ans) {
                ans = tmp;
                L = i; R = pos;
            }
        }
        else coll[a[i]] = i;
    }
    cout<<ans<<' ';
    vector<int> coll1;
    for (int i = 1; i < L; ++i) coll1.push_back(i);
    for (int i = L+1; i < R; ++i) if (a[i]<0) coll1.push_back(i);
    for (int i = R+1; i <= n; ++i) coll1.push_back(i);
    cout<<coll1.size()<<endl;
    for (int i = 0; i < (int)coll1.size(); ++i) {
        cout<<coll1[i];
        if (i == (int)coll1.size()-1) cout<<endl;
        else cout<<' ';
    }
        return EXIT_SUCCESS;
}                /* ----------  end of function main  ---------- */

care about 10^5*3*10^9=3*10^14. so you should use long long int! And ans should not be initialized as 0x3f3f3f3f, it is too small!

comments powered by Disqus