7fcb6bef04 2014-01-06 kinaba: #include <iostream> 7fcb6bef04 2014-01-06 kinaba: #include <sstream> 7fcb6bef04 2014-01-06 kinaba: #include <iomanip> 7fcb6bef04 2014-01-06 kinaba: #include <vector> 7fcb6bef04 2014-01-06 kinaba: #include <string> 7fcb6bef04 2014-01-06 kinaba: #include <map> 7fcb6bef04 2014-01-06 kinaba: #include <set> 7fcb6bef04 2014-01-06 kinaba: #include <algorithm> 7fcb6bef04 2014-01-06 kinaba: #include <numeric> 7fcb6bef04 2014-01-06 kinaba: #include <iterator> 7fcb6bef04 2014-01-06 kinaba: #include <functional> 7fcb6bef04 2014-01-06 kinaba: #include <complex> 7fcb6bef04 2014-01-06 kinaba: #include <queue> 7fcb6bef04 2014-01-06 kinaba: #include <stack> 7fcb6bef04 2014-01-06 kinaba: #include <cmath> 7fcb6bef04 2014-01-06 kinaba: #include <cassert> 7fcb6bef04 2014-01-06 kinaba: #include <tuple> 7fcb6bef04 2014-01-06 kinaba: using namespace std; 7fcb6bef04 2014-01-06 kinaba: typedef long long LL; 7fcb6bef04 2014-01-06 kinaba: typedef complex<double> CMP; 7fcb6bef04 2014-01-06 kinaba: 7fcb6bef04 2014-01-06 kinaba: class WinterAndPresents { public: 7fcb6bef04 2014-01-06 kinaba: long long getNumber(vector <int> apple, vector <int> orange) 7fcb6bef04 2014-01-06 kinaba: { 7fcb6bef04 2014-01-06 kinaba: const int N = apple.size(); 7fcb6bef04 2014-01-06 kinaba: int Xmax = 0x3fffffff; 7fcb6bef04 2014-01-06 kinaba: for(int i=0; i<N; ++i) 7fcb6bef04 2014-01-06 kinaba: Xmax = min(Xmax, apple[i]+orange[i]); 7fcb6bef04 2014-01-06 kinaba: 7fcb6bef04 2014-01-06 kinaba: LL total = 0; 7fcb6bef04 2014-01-06 kinaba: for(int X=1; X<=Xmax; ++X) { 7fcb6bef04 2014-01-06 kinaba: int am=0, aM=0; 7fcb6bef04 2014-01-06 kinaba: for(int i=0; i<N; ++i) { 7fcb6bef04 2014-01-06 kinaba: am += (X<=orange[i] ? 0 : X-orange[i]); 7fcb6bef04 2014-01-06 kinaba: aM += (X<=apple[i] ? X : apple[i]); 7fcb6bef04 2014-01-06 kinaba: } 7fcb6bef04 2014-01-06 kinaba: total += (aM-am+1); 7fcb6bef04 2014-01-06 kinaba: } 7fcb6bef04 2014-01-06 kinaba: return total; 7fcb6bef04 2014-01-06 kinaba: } 7fcb6bef04 2014-01-06 kinaba: }; 7fcb6bef04 2014-01-06 kinaba: 7fcb6bef04 2014-01-06 kinaba: // BEGIN CUT HERE 7fcb6bef04 2014-01-06 kinaba: #include <ctime> 7fcb6bef04 2014-01-06 kinaba: double start_time; string timer() 7fcb6bef04 2014-01-06 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 7fcb6bef04 2014-01-06 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 7fcb6bef04 2014-01-06 kinaba: { os << "{ "; 7fcb6bef04 2014-01-06 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 7fcb6bef04 2014-01-06 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 7fcb6bef04 2014-01-06 kinaba: void verify_case(const long long& Expected, const long long& Received) { 7fcb6bef04 2014-01-06 kinaba: bool ok = (Expected == Received); 7fcb6bef04 2014-01-06 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 7fcb6bef04 2014-01-06 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 7fcb6bef04 2014-01-06 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 7fcb6bef04 2014-01-06 kinaba: #define END verify_case(_, WinterAndPresents().getNumber(apple, orange));} 7fcb6bef04 2014-01-06 kinaba: int main(){ 7fcb6bef04 2014-01-06 kinaba: 7fcb6bef04 2014-01-06 kinaba: CASE(0) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {1}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {1}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = 3LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: CASE(1) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {1, 2, 0, 3}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {4, 5, 0, 6}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = 0LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: CASE(2) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {2, 2, 2}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {2, 2, 2}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = 16LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: CASE(3) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {7, 4, 5}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {1, 10, 2}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = 46LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: CASE(4) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {1000000}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {1000000}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = 1000002000000LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: CASE(5) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = {1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = -1LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: /* 7fcb6bef04 2014-01-06 kinaba: CASE(6) 7fcb6bef04 2014-01-06 kinaba: int apple_[] = ; 7fcb6bef04 2014-01-06 kinaba: vector <int> apple(apple_, apple_+sizeof(apple_)/sizeof(*apple_)); 7fcb6bef04 2014-01-06 kinaba: int orange_[] = ; 7fcb6bef04 2014-01-06 kinaba: vector <int> orange(orange_, orange_+sizeof(orange_)/sizeof(*orange_)); 7fcb6bef04 2014-01-06 kinaba: long long _ = LL; 7fcb6bef04 2014-01-06 kinaba: END 7fcb6bef04 2014-01-06 kinaba: */ 7fcb6bef04 2014-01-06 kinaba: } 7fcb6bef04 2014-01-06 kinaba: // END CUT HERE