int main() { ios_base::sync_with_stdio(false); FastInput in; int T=in.ReadNext(); for(int t=0;t<T;t++) { int x=abs(in.ReadNext()); int y=abs(in.ReadNext()); if(x==y) { cout<<(long long)x+y<<"\n"; } else if(x>y) { int d=(x-y); cout<<2LL*y+4LL*(d/2)+3LL*(d%2)<<"\n"; } else if(x<y) { int d=(y-x); cout<<2LL*x+4LL*(d/2)+1LL*(d%2)<<"\n"; } } return 0; }
int main() { uint32_t testcases = g_fi.ReadNext(); /* max2 = (float **)calloc(2000, sizeof(float*)); used = (int **)calloc(2000 , sizeof(int *)); for (int r = 0; r < 2000;r++) { max2[r] = (float *)calloc(2000 , sizeof(float)); used[r] = (int *)calloc(2000 , sizeof(int)); }*/ // memset(max2, 0, sizeof(float)*2000*2000); memset(used, 0, sizeof(int)*2000); for (tc = 0; tc < testcases; ++tc) { //cout<<"Test Cases "<<i<<endl; NumberofDiamonds = g_fi.ReadNext(); diamonds = (int *)malloc(NumberofDiamonds*sizeof(int *)); for (int r = 0; r < NumberofDiamonds;r++) { uint32_t S = g_fi.ReadNext(); diamonds[r] = S; } //This variable will be used to maintain the index of the lookup table which will help in DP int index = 1; //Building the lookup table for the dynamic program max2 thing. float answertc; steps = 0; int lev = ceil(log(NumberofDiamonds)/log(2)); //Sorting the Elements. //Iteration over the activity store available with us . answertc = expecteddiamondvalue(0,NumberofDiamonds-1,lev); /*for ( int i = 0;i < activitystore.size()+1;i++) { cout<<"Max t"<<i<<" "<<max2[i]; }*/ cout<<"Steps :" <<steps; printf("%f\n",answertc); // memset(max2, 0, sizeof(float)*2000*2000); for(int i=0;i<NumberofDiamonds;i++) { cout<<" i"<<used[i]<<endl; } memset(used, 0, sizeof(int)*2000); free(diamonds); } // g_fo.PrintUint(answertc, '\n'); ////cout<<"final answer : "<<a<<"After division by :"<<divis<<endl; /* for (int r = 0; r < NumberofDiamonds;r++) { free(max2[r]); free(used[r]); } free(max2); free(used);*/ g_fo.Flush(); return 0; }
int main() { //ios_base::sync_with_stdio(false); FastInput input; //FastOutput output; int nCases = input.ReadNext(); //int nCases; scanf("%d\n",&nCases); for(int caseNum=1;caseNum<=nCases;caseNum++) { nRows = input.ReadNext(); nCols = input.ReadNext(); int nNodes = 1; int w_min = INF; //max 10 int nEdges = 1; for(int i=0;i<nRows;i++) { for(int j=0;j<nCols;j++) { //grid[i][j] = input.ReadNext(); deg[nNodes] = 0; if (j-1>=0) // add it myGraph[nNodes][deg[nNodes]++] = make_pair(nNodes-1,nEdges++); if (j+1<nCols) myGraph[nNodes][deg[nNodes]++] = make_pair(nNodes+1,nEdges++); if (i-1>=0) myGraph[nNodes][deg[nNodes]++] = make_pair(nNodes-nCols, nEdges++); if (i+1<nRows) myGraph[nNodes][deg[nNodes]++] = make_pair(nNodes+nCols, nEdges++); myGrid[nNodes] = input.ReadNext()+ADD_FACTOR; w_min = min (w_min,myGrid[nNodes]); nNodes++; } } //build graph buildMyGraph(nNodes); //takes 0.482s? cerr << "Done building" << endl; //output.PrintUint(dijkstraCrazyQueue(0, nNodes, nRows*nCols),'\n'); printf("%d\n", ASP(0, nNodes, nRows*nCols,w_min)); //printf("%d\n",SPFA_SLF(nNodes,0, nRows*nCols)); } //cout <<"fart" << endl; //output.Flush(); return 0; }
int main(){ while(1){ n=in.ReadNext(); if(!n) break; for(i=1;i<=n;++i) a[i]=in.ReadNext(); st=stack<int>(); //Calculating left indices for(i=1;i<=n;++i){ while(!st.empty()){ if(a[i]<=a[st.top()]) st.pop(); else break; } if(st.empty()) sum[i]=i-1; else sum[i]=i-st.top()-1; st.push(i); } //Calculating right indices st=stack<int>(); for(i=n;i>=1;--i){ while(!st.empty()){ if(a[i]<=a[st.top()]) st.pop(); else break; } if(!st.empty()) sum[i]+=st.top()-i-1; else sum[i]+=n-i; st.push(i); } ans=0; for(i=1;i<=n;++i) ans=max(ans, (ll)a[i]*(ll)(sum[i]+1)); printf("%lld\n", ans); } return 0; }
int main() { // Taking input of number of testcases to be solved. uint32_t testcases = g_fi.ReadNext(); //Loop to go through process number of testcases time. for (uint32_t i = 0; i < testcases; ++i) { // This map will hold the level wise total score of soint. map<int,int> sointlevelscore; // This map will hold the level wise total score of sofloat. map<int,int> sofloatlevelscore; // Inputing number of Warriers in each team Soint and soFloat uint32_t sointN = g_fi.ReadNext(); uint32_t sofloatM = g_fi.ReadNext(); for ( uint32_t j = 0;j < sointN ; j++ ) { uint32_t chakra = g_fi.ReadNext(); uint32_t level = g_fi.ReadNext(); if (sointlevelscore.find(level) == sointlevelscore.end()) { sointlevelscore[level] = chakra; } else { sointlevelscore[level] = sointlevelscore.find(level)->second + chakra; } } for ( uint32_t j = 0;j < sofloatM ; j++ ) { uint32_t chakra = g_fi.ReadNext(); uint32_t level = g_fi.ReadNext(); if (sofloatlevelscore.find(level) == sofloatlevelscore.end()) { sofloatlevelscore[level] = chakra; } else { sofloatlevelscore[level] = sofloatlevelscore.find(level)->second + chakra; } } int minimumchakra = 0; //To check how much time actual logic takes /* map<int,int>::iterator chakrainterator; for ( chakrainterator = sointlevelscore.begin();chakrainterator != sointlevelscore.end();chakrainterator++) { int score = ( sofloatlevelscore[(*chakrainterator).first] - (*chakrainterator).second ); if ( score > 0 ) { minimumchakra += score; } } */ g_fo.PrintUint(minimumchakra, '\n'); } g_fo.Flush(); return 0; }
int main() { ios_base::sync_with_stdio(0); int n, m, currL, currR; node q[N]; //cin>>n; n=g_fi.ReadNext(); fo(i, n) { //cin>>dat[i]; dat[i]=g_fi.ReadNext(); } //cin>>m; m=g_fi.ReadNext(); fo(i, m) { //cin>>q[i].l>>q[i].r; q[i].l=g_fi.ReadNext(); q[i].r=g_fi.ReadNext(); q[i].l--, q[i].r--; q[i].i=i; }
int main() { FastInput obj; while(true) { hand[0] = obj.ReadNext(); hand[1] = obj.ReadNext(); hand[2] = obj.ReadNext(); if((hand[0]|hand[1]|hand[2]) == 0) return 0; sort(hand, hand+3); if(hand[0] == hand[1] && hand[1] == hand[2]) { // set if(hand[0] == 13) puts("*"); else printf("%d %d %d\n", (hand[2]+1), (hand[2]+1), (hand[2]+1)); } else if(hand[0] == hand[1]) { // pair 1 hand[2]++; if(hand[2] > 13) { hand[0]++, hand[1]++, hand[2] = 1; } sort(hand, hand+3); printf("%d %d %d\n", hand[0], hand[1], hand[2]); } else if(hand[1] == hand[2]) { // pair 2 if(hand[0] == 12 && hand[1] == 13) { puts("1 1 1"); continue; } do { hand[0]++; if(hand[0] > 13) { hand[0] = 1, hand[1]++, hand[2]++; break; } } while(hand[0] == hand[1]); sort(hand, hand+3); printf("%d %d %d\n", hand[0], hand[1], hand[2]); } else puts("1 1 2"); } }
int main() { FastInput input; //FastOutput output; int nCases = input.ReadNext(); int n,m,source,destination; int u,v,w; int i; for(int numCase=1;numCase<=nCases;numCase++) { n=input.ReadNext(); m=input.ReadNext(); source=input.ReadNext(); destination=input.ReadNext(); for(i=0;i<=n;i++) adj[i].clear(); //for(i=0;i<=n;i++) deg[i] = 0; for(i=0;i<m;i++) { u = input.ReadNext(); v = input.ReadNext(); w = input.ReadNext(); //edges[u][deg[u]++] = {w,v}; //edges[v][deg[v]++] = {w,u}; adj[u].push_back(make_pair(w,v)); adj[v].push_back(make_pair(w,u)); } SPFA_SLF(n,source,destination); /* output.PrintStr("Case #"); output.PrintUint(numCase,':'); output.PrintChar(' '); */ //cout << "Case #" << numCase <<": "; if(dist[destination]==INF) { //output.PrintStr("unreachable\n"); printf("Case #%d: unreachable\n",numCase); //cout << "unreachable" << "\n"; } else { //output.PrintUint(dist[destination],'\n'); printf("Case #%d: %d\n", numCase, dist[destination]); //cout << dist[destination] << "\n"; } } //output.Flush(); return 0; }