Cod sursa(job #671451)
| Utilizator | Data | 31 ianuarie 2012 15:08:30 | |
|---|---|---|---|
| Problema | Buline | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream>
#include<bitset>
using namespace std;
ifstream f("buline.in");
ofstream g("buline.out");
bool culoare[10005];
int n, a[10005],i, suma[10001], best[10001], bestSum,x;
int main()
{
//citire
f>>n;
for (i=1;i<=n;i++)
{
f>>a[i];
f>>x;
if(x==0)
a[i]=-a[i];
}
bestSum = a[1];
for (i = 1; i <= n; ++ i) {
best[i] = a[i];
if (best[i] < best[i-1] + a[i])
best[i] = best[i-1] + a[i];
if (bestSum < best[i])
bestSum = best[i];
}
g<<bestSum;
return 0;
}
