link: http://codeforces.com/contest/331/problem/A2
1 /* 2 ID: zypz4571 3 LANG: C++ 4 TASK: abby_a.cpp 5 */ 6 7 #include <iostream> 8 #include <cstdio> 9 #include <cstdlib> 10 #include <cstring> 11 #include <cmath> 12 #include <cctype> 13 #include <algorithm> 14 #include <queue> 15 #include <deque> 16 #include <queue> 17 #include <list> 18 #include <map> 19 #include <set> 20 #include <vector> 21 #include <utility> 22 #include <functional> 23 #include <fstream> 24 #include <iomanip> 25 #include <sstream> 26 #include <numeric> 27 #include <cassert> 28 #include <ctime> 29 #include <iterator> 30 const int INF = 0x3f3f3f3f; 31 const int dir[8][2] = {{-1,0},{1,0},{0,-1},{0,1},{-1,-1},{-1,1},{1,-1},{1,1}}; 32 using namespace std; 33 long long int a[300009], sum[300009]; 34 map<int, int> coll; 35 int main ( int argc, char *argv[] ) 36 { 37 #ifndef ONLINE_JUDGE 38 freopen("in.txt", "r", stdin); 39 #endif 40 ios::sync_with_stdio(false); 41 int n; cin>>n; 42 sum[0] = 0; 43 for (int i = 1; i<= n; ++i) { 44 cin>>a[i]; 45 sum[i] = sum[i-1] + (a[i]>=0?a[i]:0); 46 } 47 int L, R; 48 long long ans=-(long long)2e18; 49 for (int i = n; i >= 1; --i) { 50 if (coll.count(a[i]) > 0) { 51 int pos = coll[a[i]]; 52 long long tmp = a[i]*2+sum[pos-1]-sum[i]; 53 if (tmp > ans) { 54 ans = tmp; 55 L = i; R = pos; 56 } 57 } 58 else coll[a[i]] = i; 59 } 60 cout<<ans<<' '; 61 vector<int> coll1; 62 for (int i = 1; i < L; ++i) coll1.push_back(i); 63 for (int i = L+1; i < R; ++i) if (a[i]<0) coll1.push_back(i); 64 for (int i = R+1; i <= n; ++i) coll1.push_back(i); 65 cout<<coll1.size()<<endl; 66 for (int i = 0; i < (int)coll1.size(); ++i) { 67 cout<<coll1[i]; 68 if (i == (int)coll1.size()-1) cout<<endl; 69 else cout<<' '; 70 } 71 return EXIT_SUCCESS; 72 } /* ---------- 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!