ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1910. Titan Ruins: Hidden Entrance

help c++
Posted by Barbs 16 Feb 2015 21:06
#include <iostream>

using namespace std;

int main()
{
    int a[1000];
    int n=0,s,sx=0,m=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int u=1;u<n-1;u++){
            s=a[u]+a[u+1]+a[u+2];
            if(s>sx){
                sx=s;
                m=u+1;
            }}
    if (n==3){
        sx=a[0]+a[1]+a[2];
        m=2;
    }
    cout << sx << " " << m << endl;
}
Re: help c++
Posted by Sh 1 Aug 2015 18:05
#include<iostream>

using namespace std;

int main()
{
    int numSection;
    cin >> numSection;
    int a[numSection];
    for (int i = 0; i < numSection; i++)
    {
        cin >> a[i];
    }
    int n = numSection - 3 + 1;
    int max = 0;
    int middleNumSec = 0;
    for (int i = 0; i < n; i++)
    {
        if (i + 3 > numSection)
        {
            break;
        }
        int sum = 0;
        for (int j = i; j < i + 3; j++)
        {
            sum += a[j];
        }
        if (sum > max)
        {
            max = sum;
            middleNumSec = i + 2;
        }
    }
    cout << max << " " << middleNumSec << endl;

    system("pause");
    return 0;
}
Re: help c++
Posted by ELDVN 29 Oct 2015 21:25
My solution:
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <iomanip>

#define F first
#define S second
#define ll long long
#define len length()
#define sqr(x) x*x
#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define bp(x) __builtin_popcount(x)
#define INF numeric_limits<long long int>::max()
#define frp freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)

const int maxn = (int)1e6;
const int mod = (int)1e9 + 7;

using namespace std;

int n;
int a[maxn];
int sum,ans;
int cnt;

main(){
    scanf("%d",&n);
    for(int i=1; i <= n; i++){
        scanf("%d",&a[i]);
    }
    for(int i=1; i <= n-2; i++){
        sum=a[i]+a[i+1]+a[i+2];
        if(ans < sum){
            ans=sum;
            cnt=i+1;
        }
    }
    printf("%d %d",ans,cnt);


    return 0;
}
Re: help c++
Posted by Fyodor 10 Jun 2019 17:22
OMG man, thank u) this is correctly
#include <iostream>

using namespace std;

int a[1000], n = 0, s, sx = 0, m = 0;
void main()
{


    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int u = 0; u < n; u++) {
        s = a[u] + a[u + 1] + a[u + 2];
        if (s > sx) {
            sx = s;
            m = u + 2;
        }
    }