53 lines
896 B
C++
53 lines
896 B
C++
/*
|
|
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
|
|
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
|
|
VIM: let g:argv=""
|
|
*/
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <string>
|
|
|
|
int solution( std::vector<int> & a )
|
|
{
|
|
long long s = 0;
|
|
for ( auto it = a.begin(), ie=a.end(); it != ie; ++it ) {
|
|
s += *it;
|
|
}
|
|
|
|
long long t = 0;
|
|
for ( auto it = a.begin(), ie=a.end(); it != ie; ++it ) {
|
|
if ( (s-*it)%2 == 0 && t == (s-*it)/2 )
|
|
return it - a.begin();
|
|
t += *it;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
int main ( void )
|
|
{try{
|
|
#if 1
|
|
std::vector<int> a = {
|
|
-1,3,-4,5,1,-6,2,1
|
|
};
|
|
|
|
std::cout << solution( a ) << std::endl;
|
|
|
|
#endif
|
|
return 0;
|
|
}
|
|
catch ( const std::exception& e )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "std::exception(\"" << e.what() << "\")." << std::endl;
|
|
return 2;
|
|
}
|
|
catch ( ... )
|
|
{
|
|
std::cerr << std::endl
|
|
<< "unknown exception." << std::endl;
|
|
return 1;
|
|
}}
|
|
|